Hi support,
I’m trying to convert a PDF with big image (3000*3000 at least) to another PDF and reduce DPI. I’ve followed your documentation about it (Working with Images in PDF|Aspose.PDF for Java) but in the produced PDF, some images has been transform in grey background and the others are really ugly.
I think what the problem come from image extraction.
Please find below, code which produce the result :
this.document.convert(streamLogger, PdfFormat.PDF_A_1A, ConvertErrorAction.None);
this.document.validate(streamLogger, PdfFormat.PDF_A_1A.getPdf());
OptimizationOptions optimizeOptions = new OptimizationOptions();
optimizeOptions.setRemoveUnusedObjects(true);
optimizeOptions.setLinkDuplcateStreams(true;
optimizeOptions.setRemoveUnusedStreams(true);
optimizeOptions.setCompressImages(true);
optimizeOptions.setImageQuality(60);
this.document.optimizeResources(optimizeOptions);
for (Page page : this.document.getPages()) {
for (XImage image : page.getResources().getImages()) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
image.save(os, 2500, 2500);
image.replace(new ByteArrayInputStream(os.toByteArray()));
}
}
Florian
Hi Florian,
I’m apoligizing, I’m working on Linux and I always forgot format.
Open it with an image viewer.
I’ve attached images with extension.
Regards,
Florian
Hi Florian,
Hi Tilal,
Please find below the original document.
Regards,
Florian
Hi Florian,
// Internal image resolution change<o:p></o:p>
Document doc = new Document("D:\\Downloads\\PDF+with+big+images.pdf\\PDF with big images.pdf");
OptimizationOptions optimizeOptions = new OptimizationOptions();
optimizeOptions.setRemoveUnusedObjects(true);
optimizeOptions.setLinkDuplcateStreams(true);
optimizeOptions.setRemoveUnusedStreams(true);
optimizeOptions.setCompressImages(true);
optimizeOptions.setImageQuality(60);
doc.optimizeResources(optimizeOptions);
for (Page page : doc.getPages()) {
for (XImage image : page.getResources().getImages()) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
image.save(os, 2500, 2500);
image.replace(new ByteArrayInputStream(os.toByteArray()));
}
}
doc.save(myDir + "imageWithNewResolution.pdf");
Hi Tilal,
Thanks for your quick answer.
I’ve uploaded the wrong file, please find it here : MEGA
Document have a size near 60Mb and I can’t upload it on the forum.
Original document is a ODT and I’ve convert it into PDF without compression.
In my mind, the document produced by Open Office has something wrong and when Aspose open it, images are corrupted. Or in somes cases, Aspose cannot read properly images in PDF.
I have another questions about resizing, the save method with this parameters :
stream
- OutputStream where image will be savedxDpi
- Image horizontal resolutionyDpi
- Image vertical resolutionflorian.melot:
I've uploaded the wrong file, please find it here : https://mega.nz/#!tdRiBJIL
Document have a size near 60Mb and I can't upload it on the forum.
Original document is a ODT and I've convert it into PDF without compression.
In my mind, the document produced by Open Office has something wrong and when Aspose open it, images are corrupted. Or in somes cases, Aspose cannot read properly images in PDF.
florian.melot:
I have another questions about resizing, the save method with this parameters :Parameters: stream
- OutputStream where image will be savedxDpi
- Image horizontal resolutionyDpi
- Image vertical resolutionneed the size in pixels or in DPI ? In fact, method getHeight and getWidth return the size in pixels.
Oups sorry, new features on Mega
This is the key : !VKMpp7bUWO0uTbArqW4Q7TzJhJ63b4QMEwbiOZCFwbM
Regards,
Florian
florian.melot:
Thanks for your quick answer.
I've uploaded the wrong file, please find it here : https://mega.nz/#!tdRiBJIL
Document have a size near 60Mb and I can't upload it on the forum.
Original document is a ODT and I've convert it into PDF without compression.
In my mind, the document produced by Open Office has something wrong and when Aspose open it, images are corrupted. Or in somes cases, Aspose cannot read properly images in PDF.
florian.melot:
I have another questions about resizing, the save method with this parameters :Parameters: stream
- OutputStream where image will be savedxDpi
- Image horizontal resolutionyDpi
- Image vertical resolutionneed the size in pixels or in DPI ? In fact, method getHeight and getWidth return the size in pixels.
The issues you have found earlier (filed as PDFJAVA-36018) have been fixed in Aspose.Pdf for Java 11.9.0.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.