Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-3638

NullPointerException when setting form field value

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.3, 2.0.4
    • Fix Version/s: 2.0.5, 3.0.0 PDFBox
    • Component/s: AcroForm
    • Labels:
      None

      Description

      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:

      PDDocument doc = PDDocument.load(new File("input.pdf"));
      PDAcroForm form = doc.getDocumentCatalog().getAcroForm();
      form.getField("firstname").setValue("name");
      form.flatten();
      doc.save("output.pdf");
      

      Stacktrace:

      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)
      

      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 issue (see 3454)

      I attached the pdf and a screenshot with some infos from the PDFDebugger tool as requested.

      Thanks in advance.

        Attachments

        1. pdfdebugger.png
          84 kB
          Tilman Ginzel
        2. input.pdf
          100 kB
          Tilman Ginzel

          Issue Links

            Activity

              People

              • Assignee:
                tilman Tilman Hausherr
                Reporter:
                tilmanginzel Tilman Ginzel
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: