Is there an API available in iText to detect whether the PDF file has a compressed xref table?
The PdfReader class of this library has some useful API with regards to xref, but none serve my purpose.
The requirement is to:
-
Check if the PDF has xref compressed table.
-
If 1 is true -> then "Uncompress" xref table.
-
Send the byte stream for further processing.
-
Once the processing completes "Compress" back the xref table to its original form
Any pointers in this regard would be appreciated.
Posted on StackOverflow on Jan 15, 2013 by Bond - Java Bond
As it turns out, this is already supported in iText. You need to create a PdfReader instance and then use isNewXrefType().
To uncompress the XRef table of a PDF document, you can use this method:
public void uncompressXRef(String src, String dest) throws IOException, DocumentException { PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); stamper.close(); reader.close(); }
To recompress the XRef table, use this method:
public void recompressXRef(String src, String dest) throws IOException, DocumentException { PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); stamper.getWriter().setFullCompression(); stamper.close(); reader.close(); }