I am using iText to read and manipulate PDF files(reports). I read in a PDF report using iText and I save each page as a separate PDF file. But I am unable to reduce the size of the generated PDF. Is there any compression technique or any other way to reduce the size of the PDF? Does pdfbox help in this way?
You can try to set a compression level when using iText:
Document document = ...
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
writer.setCompressionLevel(9);
Level 9 is slowest, but gives you the best compression available in iText.
Please note, that the compression effect largely depends on the PDF content. If your PDF file contains large binary streams, such as images, the compression will have little to no effect on your document. Also, iText will never compress XMP metadata stream regardless of the configuration options.
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