You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2017/06/20 10:20:00 UTC

[jira] [Comment Edited] (PDFBOX-3832) PDFBox Won't Embed a Font for a Form Field if Field is Empty

    [ https://issues.apache.org/jira/browse/PDFBOX-3832?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16055510#comment-16055510 ] 

Tilman Hausherr edited comment on PDFBOX-3832 at 6/20/17 10:19 AM:
-------------------------------------------------------------------

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



was (Author: tilman):
Try set the first 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
>
> 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: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org