I have an issue when I extract an image from a pdf, reduce the quality and then replace the old image with the new in the pdf to compress the pdf.
Some image are just upside down or cut in half, etc... I don't know why this is happening.
Here is my code :
- Code: Select all
doc.loadFromFile(filename);
doc.getFileInfo().setIncrementalUpdate(false);
doc.setCompressionLevel(PdfCompressionLevel.Best);
for (int i = 0; i < doc.getPages().getCount(); i++) {
PdfPageBase page = doc.getPages().get(i);
PdfImageInfo[] images = page.getImagesInfo();
if (images != null && images.length > 0) {
for (int j = 0; j < images.length; j++) {
PdfImageInfo image = images[j];
PdfBitmap bp = new PdfBitmap(image.getImage());
bp.setQuality(8);
page.replaceImage(j, bp);
page.tryCompressImage(image.getIndex());
}
}
}
doc.saveToFile("output/" + name + "Compressed_by_Spire.pdf", FileFormat.PDF);
doc.close();
I use free spire.pdf version 5.1.0.
My pdf contains some private data, do you have an email where I can send you the uncorrect pdf ?
Thank you !