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

Can't Parse any PDF using IBM JDK

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 0.8.0-incubator
    • 0.8.0-incubator
    • Parsing
    • None
    • RedHat Linux IBM JDK

    Description

      All PDF (that I have tried) fail to parse using IBM JDK 1.5 on RedHat Linux. The error you receive is:

      Exception in thread "main" java.io.IOException: Error: Expected an integer type, actual='ãÃÃ'
      at org.apache.pdfbox.pdfparser.BaseParser.readInt(BaseParser.java:1220)
      at org.apache.pdfbox.pdfparser.PDFParser.parseObject(PDFParser.java:493)
      at org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:172)
      at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:736)
      at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:704)
      at org.apache.pdfbox.PDFReader.parseDocument(PDFReader.java:323)
      at org.apache.pdfbox.PDFReader.openPDFFile(PDFReader.java:286)
      at org.apache.pdfbox.PDFReader.main(PDFReader.java:271)

      Although after debugging the actual error is hidden:

      java.io.IOException: Error: Expected an integer type, actual='ãÏÓ'
      at org.apache.pdfbox.pdfparser.BaseParser.readInt(BaseParser.java:1220)
      at org.apache.pdfbox.pdfparser.PDFParser.parseObject(PDFParser.java:483)
      at org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:172)
      at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:736)
      at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:704)
      at org.apache.pdfbox.PDFReader.parseDocument(PDFReader.java:323)
      at org.apache.pdfbox.PDFReader.openPDFFile(PDFReader.java:286)
      at org.apache.pdfbox.PDFReader.main(PDFReader.java:271)

      The characters shown in the hidden message occur at the start of most PDF Files that I have checked:

      %PDF-1.4
      %âãÏÓ
      6 0 obj
      <</Filter /FlateDecode
      /Length 489
      >>
      stream

      Tracing the code I can see the problem is down to the skipToNextObject() method in PDFParser class. This method is new since v0.7.4.

      The code converts the array of 16 bytes to a String. The characters âãÏÓ are read as negative numbers in both Sun and IBM JDKs but whilst on Sun the String created from the byte array contains the characters on IBM JDK these characters are missing from the String. So when you read back 16 characters the stream offset is incorrect.

      Attachments

        1. IBMJDKParseFix.diff
          0.6 kB
          Jeremias Maerki
        2. ibm-parse-bug.patch
          0.4 kB
          Chris Bowditch
        3. readable.pdf
          6 kB
          Chris Bowditch

        Activity

          People

            Unassigned Unassigned
            cbowditch Chris Bowditch
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: