pdfbox-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tilman Hausherr (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (PDFBOX-4233) Flatten does not work properly on field with type 0 font
Date Thu, 07 Feb 2019 19:04:00 GMT

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

Tilman Hausherr commented on PDFBOX-4233:

Your file has empty appearance streams and needAppearances set so PDFBox should first draw
the appearances, but it doesn't do that (Adobe does). This could be done like this by the
for (PDField field : acroForm.getFieldTree())
    if (field instanceof PDTerminalField)
but it doesn't work:
java.lang.IllegalArgumentException: No glyph for U+011B (ě) in font AACDGC+TimesSansSerif
	at org.apache.pdfbox.pdmodel.font.PDCIDFontType2.encode(PDCIDFontType2.java:366)
	at org.apache.pdfbox.pdmodel.font.PDType0Font.encode(PDType0Font.java:433)
	at org.apache.pdfbox.pdmodel.font.PDFont.encode(PDFont.java:328)
	at org.apache.pdfbox.pdmodel.font.PDFont.getStringWidth(PDFont.java:357)
	at org.apache.pdfbox.pdmodel.interactive.form.PlainTextFormatter.format(PlainTextFormatter.java:195)
	at org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:507)
	at org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceContent(AppearanceGeneratorHelper.java:366)
	at org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:238)
	at org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:262)
	at org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:226)
	at org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:218)
I haven't understood all the details, but it seems that this font subset is missing some details
to encode unicode to the codes used in the PDF.

The best is not to use subsets for fonts in acroform fields. This doesn't end well, because
a user might use characters not in the font.

Another solution would be to replace the font:
PDDocument sourcePdfForm = PDDocument.load(new File("sampleform_filled.pdf"));
PDAcroForm acroForm = sourcePdfForm.getDocumentCatalog().getAcroForm();
PDResources defaultResources = acroForm.getDefaultResources();
InputStream is = new FileInputStream("c:/windows/fonts/times.ttf");
defaultResources.put(COSName.getPDFName("F5"), PDType0Font.load(sourcePdfForm, is, false));
for (PDField field : acroForm.getFieldTree())
    if (field instanceof PDTerminalField)

> Flatten does not work properly on field with type 0 font
> --------------------------------------------------------
>                 Key: PDFBOX-4233
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4233
>             Project: PDFBox
>          Issue Type: Bug
>          Components: AcroForm
>    Affects Versions: 2.0.10
>         Environment: win10, JDK 1.8
>            Reporter: rumburak
>            Priority: Major
>         Attachments: sampleform_filled.pdf, sampleform_filled_flattened.pdf, sampleform_filled_in_acrobat_reader.png
> Pdf form *sampleform_filled.pdf* contains one field called "txtField" with this content:
"ěščřžýáíéúůóďťĚŠČŘŽÝÁÍÉÚŮÓĎŤ".  The font used in this field
is "/F5"
> when you run this code:
> {code:java}
> try {
>  PDDocument sourcePdfForm = PDDocument.load(new File("sampleform_filled.pdf"));
>  PDAcroForm acroForm = sourcePdfForm.getDocumentCatalog()
>  .getAcroForm();
>  acroForm.flatten();
>  sourcePdfForm.save("sampleform_filled_flattened.pdf");
> } catch (IOException e) {
>  e.printStackTrace();
> }{code}
> You will get *sampleform_filled_flattened.pdf* with empty or not visible content of the

This message was sent by Atlassian JIRA

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org

View raw message