Travis Schneeberger created PDFBOX-3752:
-------------------------------------------
Summary: PDVariableText text color changes to be the same as the
background color after flattening
Key: PDFBOX-3752
URL: https://issues.apache.org/jira/browse/PDFBOX-3752
Project: PDFBox
Issue Type: Bug
Affects Versions: 2.0.5
Reporter: Travis Schneeberger
Fix For: 2.0.6
PDVariableText text color changes to be the same as the background color after
flattening. This effectively makes the text hidden and appear to be lost.
This includes field types such as ListBox and TextField. I don't believe I
have tested a combo box.
For example:
{code}
try(PDDocument pdfDocument = PDDocument.load(new
File("/Users/travis/Desktop/fdpAttachment2.pdf"))) {
final PDDocumentCatalog docCatalog =
pdfDocument.getDocumentCatalog();
final PDAcroForm acroForm = docCatalog.getAcroForm();
final PDField textField = acroForm.getField("Subaward Number");
textField.setValue("12345");
final PDField listBoxField = acroForm.getField("Contact for
carryforward");
listBoxField.setValue("Administrative Contact");
//when flattening with refreshAppearances, a NPE will occur if each
widget doesn't have a
//PDAppearanceDictionary instance with a normal PDAppearanceEntry
instance set PDFBOX-3751
pdfDocument.getDocumentCatalog().getAcroForm().getFields()
.stream()
.flatMap(f -> f.getWidgets().stream())
.filter(w -> w.getAppearance() == null)
.forEach(w -> {
final PDAppearanceDictionary appearance = new
PDAppearanceDictionary(new COSDictionary());
appearance.setNormalAppearance(new
PDAppearanceEntry(new COSDictionary()));
w.setAppearance(appearance);
});
pdfDocument.getDocumentCatalog().getAcroForm().flatten(pdfDocument.getDocumentCatalog().getAcroForm().getFields(),
true);
pdfDocument.save("/Users/travis/Desktop/fdpAttachment2-example-flattened.pdf");
}
{code}
Notice in the attached fdpAttachment2-example-flattened.pdf, the fields are
correctly set but the text is not visible.
If I execute the same code but do not flatten, the text is visible. See
attached fdpAttachment2-example-flattened.pdf
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]