Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

com.itextpdf.kernel.PdfException: Append mode requires a document without errors, even if recovery is possible #6

Closed
jmarxuach opened this issue Jul 23, 2020 · 9 comments

Comments

@jmarxuach
Copy link
Owner

jmarxuach commented Jul 23, 2020

Searching in google I found this that suggest there is a bug in itext7, but im not sure.

I have a PDF that throws this error, but i can't attach because is confidential.

@jmarxuach
Copy link
Owner Author

That's the exception

[main] ERROR com.itextpdf.kernel.pdf.PdfReader - Error occurred while reading cross reference table. Cross reference table will be rebuilt.
com.itextpdf.io.IOException: Error at file pointer 46,820.
at com.itextpdf.io.source.PdfTokenizer.throwError(PdfTokenizer.java:686)
at com.itextpdf.kernel.pdf.PdfReader.readXrefSection(PdfReader.java:1011)
at com.itextpdf.kernel.pdf.PdfReader.readXref(PdfReader.java:929)
at com.itextpdf.kernel.pdf.PdfReader.readPdf(PdfReader.java:677)
at com.itextpdf.kernel.pdf.PdfDocument.open(PdfDocument.java:1871)
at com.itextpdf.kernel.pdf.PdfDocument.(PdfDocument.java:324)
at com.itextpdf.signatures.PdfSigner.initDocument(PdfSigner.java:306)
at com.itextpdf.signatures.PdfSigner.(PdfSigner.java:288)
at com.itextpdf.signatures.PdfSigner.(PdfSigner.java:271)
at BatchPDFSign.lib.BatchPDFSign.signFile(BatchPDFSign.java:73)
at BatchPDFSign.portable.Main.main(Main.java:48)
Caused by: com.itextpdf.io.IOException: file position {0} cross reference entry in this xref subsection.
... 11 more
Exception in thread "main" com.itextpdf.kernel.PdfException: Append mode requires a document without errors, even if recovery is possible.
at com.itextpdf.kernel.pdf.PdfDocument.open(PdfDocument.java:1918)
at com.itextpdf.kernel.pdf.PdfDocument.(PdfDocument.java:324)
at com.itextpdf.signatures.PdfSigner.initDocument(PdfSigner.java:306)
at com.itextpdf.signatures.PdfSigner.(PdfSigner.java:288)
at com.itextpdf.signatures.PdfSigner.(PdfSigner.java:271)
at BatchPDFSign.lib.BatchPDFSign.signFile(BatchPDFSign.java:73)
at BatchPDFSign.portable.Main.main(Main.java:48)

@Jocomol
Copy link
Collaborator

Jocomol commented Jul 23, 2020

I've tried it with the sample file supplied by the OP of the question, found here. Can you the file or some similar file?

The version of iText7 the OP used was 7.0.4, we use 7.1.11. So I think the bug would be fixed already.

@jmarxuach
Copy link
Owner Author

I've tried it with the sample file supplied by the OP of the question, found here. Can you the file or some similar file?

The version of iText7 the OP used was 7.0.4, we use 7.1.11. So I think the bug would be fixed already.

I agree. Look, if I try to with following code

StampingProperties properties = new StampingProperties();

instead of

StampingProperties properties = new StampingProperties().preserveEncryption().useAppendMode();

It works !

I think useAppendModemode and preserveEncryption requires a document without errors, even if recovery is possible in itext7.

@Jocomol
Copy link
Collaborator

Jocomol commented Jul 23, 2020

#7

@Jocomol
Copy link
Collaborator

Jocomol commented Jul 23, 2020

I'll have to test if removing preserveEncyription() still works with PDF/A

@Jocomol
Copy link
Collaborator

Jocomol commented Jul 23, 2020

@jmarxuach can you try out if version 1.0.5.1 works, because I only removed .useAppendMode().

@jmarxuach
Copy link
Owner Author

@jmarxuach can you try out if version 1.0.5.1 works, because I only removed .useAppendMode().

It Works !! Even if prints the exception

[main] ERROR com.itextpdf.kernel.pdf.PdfReader - Error occurred while reading cross reference table. Cross reference table will be rebuilt.
com.itextpdf.io.IOException: Error at file pointer 46,820.
        at com.itextpdf.io.source.PdfTokenizer.throwError(PdfTokenizer.java:686)
        at com.itextpdf.kernel.pdf.PdfReader.readXrefSection(PdfReader.java:1011)
        at com.itextpdf.kernel.pdf.PdfReader.readXref(PdfReader.java:929)
        at com.itextpdf.kernel.pdf.PdfReader.readPdf(PdfReader.java:677)
        at com.itextpdf.kernel.pdf.PdfDocument.open(PdfDocument.java:1871)
        at com.itextpdf.kernel.pdf.PdfDocument.<init>(PdfDocument.java:324)
        at com.itextpdf.signatures.PdfSigner.initDocument(PdfSigner.java:306)
        at com.itextpdf.signatures.PdfSigner.<init>(PdfSigner.java:288)
        at com.itextpdf.signatures.PdfSigner.<init>(PdfSigner.java:271)
        at BatchPDFSign.lib.BatchPDFSign.signFile(BatchPDFSign.java:75)
        at BatchPDFSign.portable.Main.main(Main.java:48)
Caused by: com.itextpdf.io.IOException: file position {0} cross reference entry in this xref subsection.
        ... 11 more
[main] ERROR com.itextpdf.kernel.pdf.PdfReader - Error occurred while reading cross reference table. Cross reference table will be rebuilt.
com.itextpdf.io.IOException: Error at file pointer 46,820.
        at com.itextpdf.io.source.PdfTokenizer.throwError(PdfTokenizer.java:686)
        at com.itextpdf.kernel.pdf.PdfReader.readXrefSection(PdfReader.java:1011)
        at com.itextpdf.kernel.pdf.PdfReader.readXref(PdfReader.java:929)
        at com.itextpdf.kernel.pdf.PdfReader.readPdf(PdfReader.java:677)
        at com.itextpdf.kernel.pdf.PdfDocument.open(PdfDocument.java:1871)
        at com.itextpdf.kernel.pdf.PdfDocument.<init>(PdfDocument.java:324)
        at com.itextpdf.signatures.PdfSigner.initDocument(PdfSigner.java:306)
        at com.itextpdf.signatures.PdfSigner.<init>(PdfSigner.java:288)
        at com.itextpdf.signatures.PdfSigner.<init>(PdfSigner.java:271)
        at BatchPDFSign.lib.BatchPDFSign.signFile(BatchPDFSign.java:79)
        at BatchPDFSign.portable.Main.main(Main.java:48)
Caused by: com.itextpdf.io.IOException: file position {0} cross reference entry in this xref subsection.
        ... 11 more
[main] INFO com.itextpdf.signatures.TSAClientBouncyCastle - Timestamp generated: Thu Jul 23 14:54:01 CEST 2020

@Jocomol
Copy link
Collaborator

Jocomol commented Jul 23, 2020

@jmarxuach your pdf file is probably damaged, can you try with a similar file?

@jmarxuach
Copy link
Owner Author

@jmarxuach your pdf file is probably damaged, can you try with a similar file?

My Pdf file is 1,4 version and is created with https://wkhtmltopdf.org/ I can open it with acrobat reader DC and the signed PDF too.

Anyway, now BatchPDFSign works even if prints the exception. My PDF file is a worst case test. I have created a release v1.0.5.1

To me, issue is solved. May be I will open a new one to remember to solve the exception print.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants