We are trying to upgrade from iText 5 to iText 7 and saw few issues. I am getting an exception as "com.itextpdf.io.IOException: PDF startxref not found." inside PdfReader#readPdf() and finally in the caller method getting an exception as "com.itextpdf.kernel.PdfException: Trailer not found.".
My use case is creating PdfReader instance using inputSream and then creating PdfDocument from the reader and passing PdfWriter as a constructor parameter.We are trying to modify existing pdf, the sample code is as below
PdfReader pdfReader = new PdfReader(inputStream);
pdfReader.setUnethicalReading(true);
ByteArrayOutputStream os = new ByteArrayOutputStream();
PdfDocument pdfDocument = new PdfDocument(pdfReader, new PdfWriter(os));
Can someone, please suggest what I am doing wrong and how we can fix this issue. We have a utility method that writes the output stream and creates a new pdf attachment.
inputStreamcome from? Are you sure you are reading a correct PDF file (i.e. you can open it with an available PDF viewer tool)? Can you share a sample PDF that you have problems with? - Alexey SubachInputStreamis not positioned at the start of a pdf. I.e. either there is no valid pdf in it at all or the stream already is (partially or completely) read. - mkl