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

Empty page causes NPE in importPage

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.3.1
    • 1.4.0
    • PDModel
    • None

    Description

      An empty page does not need to have a Contents item.
      PDDocument.importPage() fails with a NullPointerException when such an empty page is imported.

          1. Eclipse Workspace Patch 1.0
            #P pdfbox
            Index: pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
            ===================================================================
          • pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (revision 1026306)
            +++ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (working copy)
            @@ -322,16 +322,19 @@
            try
            {
            PDStream src = page.getContents();
      • PDStream dest = new PDStream( new COSStream( src.getStream(), document.getScratchFile() ) );
      • importedPage.setContents( dest );
      • os = dest.createOutputStream();
        + if (src != null)
        + {
        + PDStream dest = new PDStream( new COSStream( src.getStream(), document.getScratchFile() ) );
        + importedPage.setContents( dest );
        + os = dest.createOutputStream();
      • byte[] buf = new byte[10240];
      • int amountRead = 0;
      • is = src.createInputStream();
      • while((amountRead = is.read(buf,0,10240)) > -1)
      • {
      • os.write(buf, 0, amountRead);
        + byte[] buf = new byte[10240];
        + int amountRead = 0;
        + is = src.createInputStream();
        + while((amountRead = is.read(buf,0,10240)) > -1)
        + { + os.write(buf, 0, amountRead); + }

        }
        addPage( importedPage );
        }

      Attachments

        Activity

          People

            adamnichols Adam Nichols
            kevinjackson Kevin Jackson
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: