Selvakumar Ponnusamy
Selvakumar Ponnusamy

Reputation: 5553

com.itextpdf.text.exceptions.InvalidPdfException: Rebuild failed: Error reading string at file pointer

Getting below exception while reading a PDF. It opens well in Acrobat reader. I read in another question that though its opened in acrobat its not necessary to open via iText because PDF contains an error and he recommends to fix the PDF. But the file is coming from the client and they are able to open Acrobat, so either I have to fix it or show the error or warning in Acrobat.

com.itextpdf.text.exceptions.InvalidPdfException: Rebuild failed: Error reading string at file pointer 10891; Original message: Error reading string at file pointer 10891
at com.itextpdf.text.pdf.PdfReader.readPdf(PdfReader.java:655)

Excerpt of PDF file

%PDF-1.1
1 0 obj
<<
/Creator (Developer 2000)
/CreatorDate (
/Author (Oracle Reports)
/Producer (Oracle PDF driver)
/Title (con5010I412014141258.pdf)
>>
endobj
3 0 obj
<<
/Type /Pages
/Kids 4 0 R
/Count 5 0 R
>>
endobj
7 0 obj
<</Length 8 0 R>>
stream
BT
  1. Is there any way I can show the client that the PDF has error? either via Acrobat or some other software rather Java exception.
  2. Is there way to go around this error and proceed? We faced similar issues for secured PDF and we did unlock. Please suggest

Upvotes: 4

Views: 8254

Answers (3)

Rm558
Rm558

Reputation: 5002

In my case, it allows me to use printing to fix the file.

(The printed file is basically a binary/image of the file, lots of info/metadata is lost)

enter image description here

Upvotes: 0

TurtlesAllTheWayDown
TurtlesAllTheWayDown

Reputation: 406

Edit the PDF in a text editor (notepad, notepad++, etc.) and simply add a closing parenthesis.

So the following line:
/CreatorDate (

Changes to:
/CreatorDate ()

Upvotes: 4

Selvakumar Ponnusamy
Selvakumar Ponnusamy

Reputation: 5553

It is actually a Invalid PDF. When I open the PDF in text editor I noticed that header has CreatorDate with out close bracket. I just added the close bracket with valid date like this CreatorDate (05 November 2014 17:50:24) then It works. I asked client to correct on their side

Upvotes: 6

Related Questions