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

impossible to use own TrueTypeFonts in acroForm (and font also not embedded)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Bug
    • 2.0.12, 2.0.13, 2.0.14, 2.0.15, 2.0.16
    • None
    • AcroForm, PDModel
    • None

    Description

      Hi

      I have a PDF form and want to add additional fonts, because the default fonts does not allow cyrillic or greek chars for example.

      I add the font as following (LiberationSans-Regular):

      PDResources formResources = acroForm.getDefaultResources();
      try (InputStream defaultTTFont1 = new FileInputStream(myFontFile)){
      	
      	PDFont font2 = PDType0Font.load(pdfDocument, defaultTTFont1, true);
      	COSName fontName = formResources.add(font2);
      }
      acroForm.setDefaultResources(formResources);
      

      I debugged it, the valiable ttf is set.

      When filling a text field with for example cyrillic letters an exception occurs, than I change the defaultAppereance of that field using the initially added font.
      But the original TTF will not really used, instead there wil be created new font classes with a TTF of null, so it seems to be impossible to use a different TTF.
      Furthermore the font will not be embedded in the resulting PDF.

      PDCIDFontType2.<init>(COSDictionary, PDType0Font, TrueTypeFont) line: 75	<- initialized with TrueTypeFont = null
      PDCIDFontType2.<init>(COSDictionary, PDType0Font) line: 62	
      PDFontFactory.createDescendantFont(COSDictionary, PDType0Font) line: 139	
      PDType0Font.<init>(COSDictionary) line: 192	
      PDFontFactory.createFont(COSDictionary, ResourceCache) line: 97	
      PDResources.getFont(COSName) line: 146	
      PDDefaultAppearanceString.processSetFont(List<COSBase>) line: 173	
      PDDefaultAppearanceString.processOperator(Operator, List<COSBase>) line: 132	
      PDDefaultAppearanceString.processAppearanceStringOperators(byte[]) line: 108	
      PDDefaultAppearanceString.<init>(COSString, PDResources) line: 86	
      PDTextField(PDVariableText).getDefaultAppearanceString() line: 93	
      AppearanceGeneratorHelper.<init>(PDVariableText) line: 100	
      PDTextField.constructAppearances() line: 263	
      PDTextField(PDTerminalField).applyChange() line: 228	
      PDTextField.setValue(String) line: 219	
      

      As a result of this behavoir I get the following warning:

      WARN  org.apache.pdfbox.pdmodel.font.PDCIDFontType2 - Using fallback font LiberationSans for CID-keyed TrueType font LiberationSans-Regular
      

      When opening the PDF afterwards, I will get an error from AcrobatReader, that the font "LiberationSans-Regular" could be found, because the font is not embedded... like my own fonts..

      I tried it back to version 2.0.12 - always the same behavior.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              chandre André Hertwig
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: