[ 
https://issues.apache.org/jira/browse/PDFBOX-3832?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tilman Hausherr updated PDFBOX-3832:
------------------------------------
    Comment: was deleted

(was: Try set the third parameter to false when loading your font
{code:java}
PDType0Font.load(doc, is, false);
{code}
)

> PDFBox Won't Embed a Font for a Form Field if Field is Empty
> ------------------------------------------------------------
>
>                 Key: PDFBOX-3832
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3832
>             Project: PDFBox
>          Issue Type: Bug
>          Components: AcroForm, FontBox
>    Affects Versions: 2.0.5, 2.0.6
>            Reporter: Evan Williams
>             Fix For: 2.0.7, 3.0.0
>
>
> When working with AcroForms, attempting to se the font of a form field, the 
> font will only properly embed if the form field contains at least one 
> character. Fonts set on empty fields do not embed. The font is only embedded 
> if it is actually used.
> Example code:
> {code:Java}
>         final PDFont formFont = loadFontResourceWithDef(pdf, 
> DEFAULT_FONT_PATH,
>                 DEF_DOCUMENT_FONT);
>         final PDResources resources = acroForm.getDefaultResources();
>         final String fontName = resources.add(formFont).getName();
>         acroForm.setDefaultResources(resources);
>         this.defaultAppearanceString = "/" + fontName + " 0 Tf 0 g";
>     }
>     public static PDFont loadFontResourceWithDef(PDDocument doc,
>             String fontpath, PDFont defFont) {
>         PDType0Font resFont = null;
>         try {
>             final InputStream is = 
> this.getClass().getResourceAsStream(fontpath);
>             if (is != null) {
>                 resFont = PDType0Font.load(doc, is);
>             }
>         } catch (IOException e) {
>             log("Error loading font " + fontpath, e);
>         }
>         return resFont != null ? resFont : defFont;
>     }
> {code}
> Presume that I have verified that the font actually is loaded into the 
> formFont variable.
> Some time later, I iterate over the fields in the acroform and, for each 
> field, do this:
> {code:Java}
>             if (field instanceof PDTextField) {
>                 final PDTextField textfield = (PDTextField) field;
>                 textfield.setDefaultAppearance(defaultAppearanceString);
>             }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to