Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

pdf

itext

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
like image 748
Selvakumar Ponnusamy Avatar asked Jan 09 '23 22:01

Selvakumar Ponnusamy


2 Answers

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

like image 123
Selvakumar Ponnusamy Avatar answered Jan 28 '23 06:01

Selvakumar Ponnusamy


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

So the following line:
/CreatorDate (

Changes to:
/CreatorDate ()

like image 38
TurtlesAllTheWayDown Avatar answered Jan 28 '23 08:01

TurtlesAllTheWayDown