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

Tilman Ginzel commented on PDFBOX-3454:
---------------------------------------

I cannot reproduce the issue with the given example pdf using 2.0.3 and 2.0.4, 
so it seems to be fixed there.

If I use our pdf (unfortunately I cannot share it), I get black borders with 
version 2.0.2, as expected.
Using 2.0.3 oder 2.0.4 I get a NullPointerException, while trying to set a 
value to a PDTextField.
Sorry, I thought I'd still get the black borders issue, but that was before 
using 2.0.3.

I tried to debug the problem, maybe it is another issue or a problem with our 
pdf.

Here is a minimal java example.

{code:title=Main.java}
PDDocument doc = PDDocument.load(new File("input.pdf"));
PDAcroForm form = doc.getDocumentCatalog().getAcroForm();
form.getField("userdata1.name").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 
{code}
form.setNeedAppearances(true);
{code}
before setting the value, the NullPointerException is gone. But then 
_flatten()_ does break something, all form fields are empty in the resulting 
pdf.

Could this be a problem with our pdf? Should I open another issue with an 
example pdf or am I doing something obviously wrong?


> Wrong color and line setting when filling a form
> ------------------------------------------------
>
>                 Key: PDFBOX-3454
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3454
>             Project: PDFBox
>          Issue Type: Bug
>          Components: AcroForm
>    Affects Versions: 2.0.0, 2.0.1, 2.0.2
>            Reporter: Maruan Sahyoun
>              Labels: Appearance
>         Attachments: Change of Address Form.pdf, rendered-1.png
>
>
> As reported on so 
> http://stackoverflow.com/questions/38724499/rendering-a-document-with-filled-form-fields-using-pdfbox-works-with-1-8-2-but
>  the form fields are not rendered correctly using PDFBox 2.0.x. That's due to 
> not setting the line and color information correctly.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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

Reply via email to