Search code examples
debuggingpdfpdf-generationacrobatpdfclown

Debugging PDF for error


I'm creating PDF files using PDFClown java library.

Sometimes, when openning these files with Adobe Acrobat Reader I get the famous error message:

"An error exists on this page. Acrobat may not display the page correctly. Please contact the person who created the PDF document to correct the problem."

The error shows while reading (with Adobe) the attached file only when scrolling down to the 8'th page, then scrolling back up to 3'td page. Alternatively, Zooming out to 33.3% will also produce the message.

Just for the record, Foxit reader reads the file flawlessly, as well as other PDF readers like browsers.

My questions are:

  1. What's wrong with my file?? (file is attached)

  2. How can I find what's wrong with it? is there a tool which tells you where does the error lie?

Thanks!


Solution

  • Ok, this wasn't easy -

    Due to a bug in PDFClown the my main stream of information in the PDF page has been corrupted. After it's end it had a copy of a past instance of it. This caused a partial text section without the starting command "BT" - which left a single "ET" without a "BT" in the end of the stream.

    once I corrected this, it ran great.

    Thank you all for your help. I would have much more difficult time debugging it without the tool RUPS which @Bruno suggested.

    edit:

    The bug was in the Buffer.java:clone() (line 217)

    instead of line:

    clone.append(data);

    needs to be:

    clone.append(data, 0, this.length);

    Without this correction it clones the whole data buffer, and set the cloned Buffer's length to the data[].length. This is very problematic if the Buffer.length is smaller than the data[].length. The result in my case was that in the end of the stream there was garbage.