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

PDPage.convertToImage throwing an uncaught IOException internally

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.1, 1.3.1, 1.5.0
    • Fix Version/s: 1.6.0
    • Component/s: PDModel
    • Labels:
    • Environment:
      Windows 7, jdk1.6.0_21

      Description

      After successfully loading a PDF document and extracting pages from it using the following snippet:

      doc = PDDocument.load(f);
      pages = doc.getDocumentCatalog().getAllPages();

      I try and convert the front page to an image as follows:

      PDPage page = (PDPage) pages.get(0);
      BufferedImage image = page.convertToImage();

      The page.convertToImage() causes a RuntimeException to be thrown due to an uncaught internal IOException. Otherwise, the extracting of text/images and all other functions I tried work correctly on this document.

      Here is the stack trace:

      Exception in thread "main" java.lang.RuntimeException: java.io.IOException: The handle is invalid
      at org.apache.pdfbox.pdfparser.PDFStreamParser$1.tryNext(PDFStreamParser.java:149)
      at org.apache.pdfbox.pdfparser.PDFStreamParser$1.hasNext(PDFStreamParser.java:158)
      at org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:241)
      at org.apache.pdfbox.util.PDFStreamEngine.processStream(PDFStreamEngine.java:208)
      at org.apache.pdfbox.pdfviewer.PageDrawer.drawPage(PageDrawer.java:112)
      at org.apache.pdfbox.pdmodel.PDPage.convertToImage(PDPage.java:722)
      at org.apache.pdfbox.pdmodel.PDPage.convertToImage(PDPage.java:693)
      at pdfboxtestant.Main.getFrontPageImage(Main.java:44)
      at pdfboxtestant.Main.main(Main.java:25)
      Caused by: java.io.IOException: The handle is invalid
      at java.io.RandomAccessFile.seek(Native Method)
      at org.apache.pdfbox.io.RandomAccessFile.seek(RandomAccessFile.java:59)
      at org.apache.pdfbox.io.RandomAccessFileInputStream.read(RandomAccessFileInputStream.java:96)
      at java.io.BufferedInputStream.read1(BufferedInputStream.java:256)
      at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
      at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
      at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
      at java.io.FilterInputStream.read(FilterInputStream.java:66)
      at java.io.PushbackInputStream.read(PushbackInputStream.java:122)
      at org.apache.pdfbox.io.PushBackInputStream.read(PushBackInputStream.java:84)
      at org.apache.pdfbox.pdfparser.BaseParser.skipSpaces(BaseParser.java:1296)
      at org.apache.pdfbox.pdfparser.PDFStreamParser.parseNextToken(PDFStreamParser.java:197)
      at org.apache.pdfbox.pdfparser.PDFStreamParser.access$000(PDFStreamParser.java:47)
      at org.apache.pdfbox.pdfparser.PDFStreamParser$1.tryNext(PDFStreamParser.java:146)
      ... 8 more

        Attachments

        1. document.pdf
          5.34 MB
          Kosta Krauth

          Issue Links

            Activity

              People

              • Assignee:
                lehmi Andreas Lehmkühler
                Reporter:
                kosta Kosta Krauth
              • Votes:
                2 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: