Image quality in PDF

Hi,

I have been trying to use the OptimizationOptions class to set the image quality in our PDF documents by using the setMaxResolution(int value). I have also tried using setImageQuality(int value) method. The use of setImageQuality certainly works but I can’t seem to get any effect using setMaxResolution.

The code sample is something like;

com.aspose.pdf.Document pdfDoc = new com.aspose.pdf.Document(“sample_document.pdf”);
OptimizationOptions optOptions = new OptimizationOptions();
optOptions.setMaxResoultion(72);
pdfDoc.optimizeResources(optOptions);
pdfDoc.save(“maxRes_sample_document.pdf”);

But it seems no matter what value I use the quality of the image (visually) and the size of the PDF doesn’t change. - I think I’m missing something?

Regards
Bart.

@BartMorse

Thank you for contacting support.

Would you please share source and generated files with us so that we may try to reproduce and investigate it in our environment. Before sharing requested data, please ensure using Aspose.PDF for Java 19.3.

Attached is a zip with my sample input and the output files.
Regards
Bart.Sample_files.zip (1.5 MB)

@BartMorse

Thank you for sharing requested data.

We have been able to notice that change in values does not make any difference. Therefore, a ticket with ID PDFJAVA-38504 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.

@BartMorse

We have resolved the earlier logged ticket. Please enable setCompressImages(true) to convert images during optimization:

OptimizationOptions optOptions = new OptimizationOptions();

int quality = 50;
optOptions.getImageCompressionOptions().setCompressImages(true);
optOptions.getImageCompressionOptions().setImageQuality(quality);
pdfDoc.optimizeResources(optOptions);

Also, to activate setMaxResoultion(72) - you should enable image resize using setResizeImages(true);:

com.aspose.pdf.Document pdfDoc = new com.aspose.pdf.Document(dataDir+"sample_document.pdf");
OptimizationOptions optOptions = new OptimizationOptions();

optOptions.getImageCompressionOptions().setResizeImages(true);        
optOptions.getImageCompressionOptions().setMaxResolution(72);

int quality = 50;
optOptions.getImageCompressionOptions().setCompressImages(true);
optOptions.getImageCompressionOptions().setImageQuality(quality);

pdfDoc.optimizeResources(optOptions);
pdfDoc.save(dataDir+"sample_document_21_5_quality"+quality+"_maxResolution72_out.pdf");