Free Support Forum - aspose.com

PDF File Size too large - OptimizationOptions doesn't work


#1

Hello,

We’ve changed from ApacheFOP in Java to AsposePDF.Net.
The filesize of the pdf-files generated by ApacheFOP were around 5 KB.
The filesize of the pdf-files generated by AsposePDF are around 80-90 KB.

I’ve included following optimization code, which i’ve found in the forum, but it didn’t helped.
The filesize is still the same (actually it’s a little bit larger with optimization?)

It’s important for us to minimize the filesize as small as possible.
Do you have any ideas?
Thank you!

        Document m_asposepdf = new Document(inStr, xslLoadOptions);

        //ImageCompressionOptions ImageCompressionOptions = new ImageCompressionOptions();
        //ImageCompressionOptions.CompressImages = true;
        //ImageCompressionOptions.ImageQuality = 12;
        //ImageCompressionOptions.ResizeImages = true;
        //m_asposepdf.OptimizeResources(new OptimizationOptions()
        //{
        //    LinkDuplcateStreams = true,
        //    RemoveUnusedObjects = true,
        //    AllowReusePageContent = true,
        //    RemoveUnusedStreams = true,
        //    UnembedFonts = false
        //});
        //m_asposepdf.Optimize();

        MemoryStream outStream = new MemoryStream();
        m_asposepdf.Save(outStream);

Sincerly,
Robin


#2

@robinrehbein

Thanks for contacting support.

Could you please share your sample PDF document with us. We will test the scenario in our environment and address it accordingly.


#3

@asad.ali
Hello,

here are the two PDFs.
optimized.pdf (92.8 KB)
unoptimized.pdf (92.7 KB)

It would be great, if we have a solution tomorrow.

Sincerly,
Robin


#4

Here is an other example with the given XML-FO Document which was used to generate the PDF Files
example.zip (258.6 KB)


#5

@robinrehbein

Thanks for providing further information.

We have checked the document shared by you and noticed that input PDF has fonts embedded in it which contributes more in increasing its size. Using optimizationOptions.UnembedFonts = true; option unembeds the fonts and size of the PDF document is decreased. Please check following code snippet:

Document doc = new Document(dataDir + @"unoptimized.pdf");
var optimizationOptions = new Aspose.Pdf.Optimization.OptimizationOptions();
optimizationOptions.RemoveUnusedObjects = true;
optimizationOptions.RemoveUnusedStreams = true;
optimizationOptions.AllowReusePageContent = true;
optimizationOptions.LinkDuplcateStreams = true;
optimizationOptions.UnembedFonts = true;
optimizationOptions.ImageCompressionOptions.CompressImages = true;
optimizationOptions.ImageCompressionOptions.ImageQuality = 50;
optimizationOptions.ImageCompressionOptions.ResizeImages = true;
doc.OptimizeResources(optimizationOptions);
doc.Optimize();
doc.Save(dataDir + @"ExampleOptimized_19.5.pdf");

ExampleOptimized_19.5.pdf (23.6 KB)

In case this optimized size is still not satisfactory for you, please share the optimized PDF obtained from other utility you mentioned. We will further proceed to assist you accordingly.


#6

Thank you for your answer. This is for now a great solution. It’s like the same, what i did in a different sequence or am i wrong?

Here is an older PDF File. The filesize of this is ~4 KB.
apache_fop_pdf.pdf (3.5 KB)

The same with Aspose is ~18 KB. So if there is any chance to minimize the filesize further more, it would be great.
aspose_19.5_pdf.pdf (17.5 KB)

Right now, we can work with the current filesize.

Sincerly Robin


#7

@robinrehbein

Thanks for your feedback.

The sequence of the lines of code does not matter - however, you did not set font embedding as true in your code snippet.

Furthermore, an investigation ticket as PDFNET-46397 has been logged in our issue tracking system. We will further compare both output PDF document and check feasibility to reduce PDF size more as per your expectations. As soon as we have some definite updates regarding ticket resolution, we will share with you. Please spare us little time.

We are sorry for the inconvenience.


#8

@asad.ali

Thanks for your support!
I hope you can find a way to reduce the PDF sice further more.

Sincerly,
Robin


#9

@robinrehbein

Sure, we will let you know as soon as we have some updates to share.