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

NullPointerException when trying to merge PDFs

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1.0
    • 1.2.0
    • Utilities
    • None
    • Windows Vista 32-bit, Java 1.5.0_06, PDFBox HEAD tag (revision 937101)

    Description

      I was trying to use the PDFMergerUtility class to merge some PDFs. Using the unmodified PDFBox source, I get a NullPointerException when I call mergeDocuments(). I made two different copies of the same file to make sure it wasn't caused by something like file access. The file opens fine with Adobe Acrobat, and PDFBox can load the document with no problem, so it doesn't seem to be a corrupt PDF in this case. I'm not familiar with the PDOutlineNode class, so I'm not sure where to go from here. I will attach the PDF I'm using to this bug report. If there's anything else I can provide let me know.

      Code:
      public static void main(String[] args) {
      String inputFile0 = "C:
      US_Constitutional_Ammendments_copy.pdf";
      String inputFile1 = "C:
      US_Constitutional_Ammendments.pdf";
      String outputFile = "C:
      US_Constitutional_Ammendments_output.pdf";
      try

      { PDFMergerUtility pdfMergerUtil = new PDFMergerUtility(); pdfMergerUtil.setDestinationFileName(outputFile); pdfMergerUtil.addSource(inputFile0); pdfMergerUtil.addSource(inputFile1); pdfMergerUtil.mergeDocuments(); System.out.println("Yay, nothing went wrong."); }

      catch(Exception e)

      { System.out.println("Oh no, something went wrong!"); e.printStackTrace(); }

      }

      java.lang.NullPointerException
      at org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineNode.setParent(PDOutlineNode.java:108)
      at org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineNode.appendChild(PDOutlineNode.java:118)
      at org.apache.pdfbox.util.PDFMergerUtility.appendDocument(PDFMergerUtility.java:303)
      at org.apache.pdfbox.util.PDFMergerUtility.mergeDocuments(PDFMergerUtility.java:193)
      at com.xldynamics.common.MergeTest.main(MergeTest.java:35)

      Attachments

        1. PDFBOX-700.patch
          0.8 kB
          Adam Nichols
        2. US_Constitutional_Ammendments_copy.pdf
          145 kB
          Adam Nichols
        3. US_Constitutional_Ammendments.pdf
          145 kB
          Adam Nichols

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            adamnichols Adam Nichols
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment