Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-3597

PDAcroForm.refreshAppearances() does not respect updated fonts

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.0.3
    • None
    • PDModel
    • None

    Description

      I have attached example files in the External issue URL link.

      I am trying to embed a subset of a font into my pdf after populating the fields. If I don't run refreshAppearances() the values will be put into the fields, but will only be visible when the field is selected (likely another bug).

      To work around this, I am trying to set the default appearance on the fields manually to reflect the embedded font. If I embed the whole font, it works as expected, however when I try to embed a subset of the font it fails:
      Exception in thread "main" java.lang.IllegalArgumentException: No glyph for U+540D in font AAWTXC+ArialUnicodeMS
      at org.apache.pdfbox.pdmodel.font.PDCIDFontType2.encode(PDCIDFontType2.java:400)
      at org.apache.pdfbox.pdmodel.font.PDType0Font.encode(PDType0Font.java:351)
      at org.apache.pdfbox.pdmodel.font.PDFont.encode(PDFont.java:316)
      at org.apache.pdfbox.pdmodel.font.PDFont.getStringWidth(PDFont.java:345)
      at org.apache.pdfbox.pdmodel.interactive.form.PlainTextFormatter.format(PlainTextFormatter.java:195)
      at org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:422)
      at org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceContent(AppearanceGeneratorHelper.java:288)
      at org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:170)
      at org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:263)
      at org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm.refreshAppearances(PDAcroForm.java:318)
      at test_pdfbox.TestPDFBox.main(TestPDFBox.java:45)

      It would appear that after I call form.setDefaultResources with the updated font, refreshAppearances is still trying to use the old font as the appearance, although I may be wrong.

      Expected:
      appearances are updated, subset of font is embedded.

      Attachments

        Activity

          People

            Unassigned Unassigned
            misterwise Matt Wise
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: