We use iText
version 5.5 PdfCopy
to merge multiple tagged PDFs. (Those tagged PDFs are not created by iText
.) We got the following error while document.close
:
java.lang.NullPointerException
at com.itextpdf.text.pdf.RefKey.<init>(RefKey.java:59)
at com.itextpdf.text.pdf.PdfCopy.fixTaggedStructure(PdfCopy.java:822)
at com.itextpdf.text.pdf.PdfCopy.flushTaggedObjects(PdfCopy.java:779)
at com.itextpdf.text.pdf.PdfDocument.close(PdfDocument.java:854)
at com.itextpdf.text.Document.close(Document.java:416)
com.itextpdf.text.exceptions.InvalidPdfException: Rebuild failed: trailer not found.; Original message: PDF startxref not found.
at com.itextpdf.text.pdf.PdfReader.readPdf(PdfReader.java:668)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:181)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:230)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:207)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:197)
PDF are valid and contains trailer and %EOF
, Files are not corrupted. What other could cause this?
You may have found the answer already. I had the same issue and I solved it by closing the document before instantiating PdfReader.
Example:
**
Document tempDoc = new Document(PageSize.A4, 40, 40, 80, 20);
ByteArrayOutputStream tempBaos = new ByteArrayOutputStream();
PdfWriter.getInstance(tempDoc, tempBaos);
tempDoc.open();
tempDoc.add(tempChap);
tempDoc.close(); // Closing the document before calling Reader
PdfReader reader = new PdfReader(tempBaos.toByteArray());
**
Hope this will help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With