Tilman Ginzel created PDFBOX-3638:
-------------------------------------
Summary: NullPointerException when setting form field value
Key: PDFBOX-3638
URL: https://issues.apache.org/jira/browse/PDFBOX-3638
Project: PDFBox
Issue Type: Bug
Components: AcroForm
Affects Versions: 2.0.4, 2.0.3
Reporter: Tilman Ginzel
NullPointerException when setting form field value
Hi,
I am not able to fill out form fields using 2.0.3 or 2.0.4.
When calling {{field.setValue("value")}} I get a NullPointerException.
Code:
{code}
PDDocument doc = PDDocument.load(new File("input.pdf"));
PDAcroForm form = doc.getDocumentCatalog().getAcroForm();
form.getField("firstname").setValue("name");
form.flatten();
doc.save("output.pdf");
{code}
Stacktrace:
{code}
Exception in thread "main" java.lang.NullPointerException
at
org.apache.pdfbox.pdmodel.PDPageContentStream.getName(PDPageContentStream.java:964)
at
org.apache.pdfbox.pdmodel.PDPageContentStream.setNonStrokingColor(PDPageContentStream.java:1172)
at
org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.initializeAppearanceContent(AppearanceGeneratorHelper.java:211)
at
org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:167)
at
org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:263)
at
org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:228)
at
org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:218)
{code}
The private property PDResources resources is null.
If I set {{form.setNeedAppearances(true);}} before setting the value, the
NullPointerException is gone. But then {{form.flatten()}} does break something,
all form fields are empty in the resulting pdf.
Maybe this is an issue with our pdf. The same code works using version 2.0.2,
but there I suffer from the black border isse (see 3454)
I attached the pdf and a screenshot with some infos from the PDFDebugger tool
as requested.
Thanks in advance.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]