Optimize for Web

I have a pdf given to me by our drafting department. It is 1112KB in size. If I open the document in Acrobat and take the option to “Optimize Pdf” and take the standard settings the doc is reduced to 805KB.

Whe I use Aspose PDF and use either optimize() or optimizeResources() there is no size change.

When I use optimizeResources with an OptimizationOptions class set to remove everything and compress images I can get the size as low as 1009KB if I set the imageQuality to 5…

I tried using the ximage method and the file increased to 8000KB…

All I need this to do is the same thing Acrobat does and optimize the file for the web, but all of the examples provided on the forum fall far short of this goal.

What do I need to do?

Jon

Hi Jon,


Thanks for your inquiry. We will appreciated it if you please share your sample PDF here, so we will look into it and will guide you accordingly.

We are sorry for the inconvenience caused.

Best Regards,

I just attached the pdf to the original post.

Hi Jon,


Thanks for sharing the source file. I have tested the scenario and notice the difference in size of files optimized using Adobe and Aspose.Pdf. So logged an investigation ticket PDFNEWNET-37901 in our issue tracking system for further investigation. We will notify you as soon as we resolve the issue.

We are sorry for the inconvenience caused.

Best Regards,

Where are we on this ticket? I cannot complete my project without being able to optimize the pdfs.

Jon

Hi Jon,


Thanks for your inquiry. I am afraid we have recently noticed the issue and it is pending for investigation due to the issues already under investigation.We have recorded your concern and as soon as investigation is completed then we will share our findings/ETA with you. We will keep you updated about the issue resolution progress.

Thanks for your patience and cooperation.

Best Regards,

I has been a month since I sent this issue in, and I still haven’t heard anything. I have a project waiting on this? Is this going to be resolved or do I need to find another tool?

Jon

Hi Jon,


Thanks for your patience.

As shared earlier, the issue is pending for review as it’s been recently reported. Please
note that as a normal rule of practice, issues are resolved in first come and
first serve basis; but the problems logged/reported under Enterprise or
Priority support model, have high precedence in terms of resolution, as compare
to issues under normal/free support model. Nevertheless, as soon as we have some further updates, we will let you know.

Hi,


i have the same issue like Jon.

Using your example input.pdf and code:
String dataDir = “src/programmersguide/workingwithasposepdf/workingwithdocument/optimizepdfdocument/data/”;

//Open document
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(dataDir+ “input.pdf”);
//Optimize for web
pdfDocument.optimize();
//Save output document
pdfDocument.save(“Optimized_output.pdf”);

makes even the pdf-file larger…
Setting the OptimizationOptions dont make it better.
kindly regards
ToYi

ToYi:
Hi,

i have the same issue like Jon.

Using your example input.pdf and code:
String dataDir = “src/programmersguide/workingwithasposepdf/workingwithdocument/optimizepdfdocument/data/”;

//Open document
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(dataDir+ “input.pdf”);
//Optimize for web
pdfDocument.optimize();
//Save output document
pdfDocument.save(“Optimized_output.pdf”);

makes even the pdf-file larger…
Setting the OptimizationOptions dont make it better.
kindly regards
ToYi
Hi ToYi,

Thanks for contacting support.

Please share your source PDF file so that we can test the scenario in our environment. We apologize for this inconvenience.

Hi,


i attached the file. it was the example pdf.file from your aspose-pdf examples.

kindly regards
ToYi

Hi ToYi,


Thanks for sharing the resource file.

The optimize(…) method is used to enable Fast web view but in case you need to reduce the PDF file size, please try using optimizeResources(…) method.

[Java]

//Open
document
<o:p></o:p>

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("c:/pdftest/input (1).pdf");

com.aspose.pdf.Document.OptimizationOptions optimize = new com.aspose.pdf.Document.OptimizationOptions();

optimize.setCompressImages(true);

optimize.setRemoveUnusedObjects(true);

optimize.setRemoveUnusedStreams(true);

//optimize.setUnembedFonts(true);

//Optimize file size

pdfDocument.optimizeResources(optimize);

//Save output document

pdfDocument.save("c:/pdftest/Optimized_output.pdf");

pdfDocument.optimize();


However as per my observations, when executing the above stated code, the resultant file size is same as input PDF document. But if we call optimize.setUnembedFonts(true); method, the size is reduced to 51 KB but when viewing the resultant file, font for file contents is changed (Calibri font embedded inside source file is removed). For your reference, I have also attached the resultant file generated over my end.

Hi Nayyer,


thx for your fast response.

I already used the optimizeResources method, but no changes recognized.

For pdf-files with images i’ve used the compress methode:

Document.OptimizationOptions opt = new Document.OptimizationOptions();
opt.setCompressImages ( true );
// Set the quality of images in PDF file
opt.setImageQuality ( 10 );
doc.optimizeResources(opt);

But executing this code results with an exception:

java.lang.IllegalArgumentException: Map size (0) must be >= 1


kindly regards
ToYi

ToYi:
Hi Nayyer,

thx for your fast response.

I already used the optimizeResources method, but no changes recognized.

For pdf-files with images i've used the compress methode:

Document.OptimizationOptions opt = new Document.OptimizationOptions();
opt.setCompressImages ( true );
// Set the quality of images in PDF file
opt.setImageQuality ( 10 );
doc.optimizeResources(opt);

But executing this code results with an exception:

java.lang.IllegalArgumentException: Map size (0) must be >= 1


kindly regards
ToYi
Hi ToYi,

Please share the resource files causing this problem so that we can test the scenario in our environment. We are sorry for this inconvenience.

Hi Nayyer,


its a scanned doc converted to pdf. Even images converted to pdf doesnt work.

When is this bug resolved?

kindly regards
ToYi

Hi Toyi,


Thanks for your patience.

The development team has further investigated the issue reported earlier and as per our observations, when document is optimized with Acrobat, its ColorSpace resource is updated (was N = 4; Length = 389757 and is changed to of N = 3; Length = 2574). We have not been able to figure out whey its happening but we will be further investigation this issue and will keep you posted with our findings.
Hi,

any news here? It is now 7 months without update.
Can you do same thing like Adobe with change of ColorSpace?

I need fix for .NET version.

Thanks,
Oliver

dr_oli:
any news here? It is now 7 months without update.
Hi Oliver,

Thanks for your patience.

I am afraid the earlier reported issue is still not resolved. However I have intimated the development team to share the current status regarding its resolution. As soon as we have some further updates, we will let you know.
dr_oli:
Can you do same thing like Adobe with change of ColorSpace?
Do you need the requirement to convert RGB colorspace PDF to GrayScale document ? If so is the case, then please visit the following link for related information on Convert a PDF from RGB colorspace to Grayscale

Hi,

can you check you comment from 01-28-2015, 1:02 PM?
You compared Adobe compressed vs. Aspose compressed document and wrote that Adobe changed ColorSpace from value N=4 to N=3 and that reduced size from 389757 to 2574.

As this is huge it will be good to get feedback on this topic as this might be great improvement in Aspose compression functionality.

P.S. Is there any way to enforce this change through current object model?

Thanks,
Oliver

Hi Oliver,


Thanks for your feedback. I am afraid the subjected issue of optimization is still not resolved due to its complexity and changes required in API.

Yes you are right improvement in compression functionality of Aspose.Pdf would be a good value addition. We have raised the issue priority in our issue tracking system. We will notify you as soon as we made some significant progress towards issue resolution.

Best Regards,