Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Sep 02, 2020 12:00 am

I am trialing your software in an attempt to compress a PDF in file size. I know the file can be compressed because if use various web tools - these reduce them by about 75% (pdf2go, etc). I am using the example code from the following website but it is not resulting in any smaller of PDF. What am I doing wrong?

The example code can be found here - it is too big to upload as part of this ticket...

omnant [dot] com/PdfCompression.Iceblue.zip

chad_omnant
 
Posts: 3
Joined: Tue Sep 01, 2020 11:52 pm

Wed Sep 02, 2020 9:53 am

Hello,

Thanks for your inquiry.
I noticed that your PDF file mainly contains images, you can use the “TryCompressImage”method to directly compress images in PDF files, below is the corresponding code for your reference. If there are any questions, please feel free to write back.
Code: Select all
public static void CompressContent(PdfDocument doc)
        {
            //Disable the incremental update
            doc.FileInfo.IncrementalUpdate = false;

            //Set the compression level to best
            doc.CompressionLevel = PdfCompressionLevel.Best;
        }

        public static void CompressImage(PdfDocument doc)
        {
            //Disable the incremental update
            doc.FileInfo.IncrementalUpdate = false;

            //Traverse all pages
            foreach (PdfPageBase page in doc.Pages)
            {
                if (page != null)
                {
                    if (page.ImagesInfo != null)
                    {
                        foreach (PdfImageInfo info in page.ImagesInfo)
                        {
                            page.TryCompressImage(info.Index);
                        }
                    }
                }
            }
        }

        public static void Main(string[] args)
        {
           
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile("Drawing.pdf");
            //Compress the content in document
            CompressContent(pdf);

            //Compress the images in document
            CompressImage(pdf);

            //Save the document
            pdf.SaveToFile("CompressDocument_result.pdf");
        }



Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Mon Sep 07, 2020 3:59 pm

Thanks for the response. I was able to incorporate your code into my example. However, it only took the file from 14.5 MB to 11.5 MB. Is this the best expectation I should have with your toolkit?

chad_omnant
 
Posts: 3
Joined: Tue Sep 01, 2020 11:52 pm

Tue Sep 08, 2020 8:09 am

Hello,

Thanks for your feedback.
Since your document contains a lot of images, I am worried that it may be difficult to compress your file even smaller using our Spire.PDF. However, I have posted this issue to our Dev team and they will investigate whether the file size can be further optimized. If there is any good news, we will inform you.

Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Tue Sep 15, 2020 5:32 pm

Checking in to see if there was any update on this issue.

chad_omnant
 
Posts: 3
Joined: Tue Sep 01, 2020 11:52 pm

Wed Sep 16, 2020 3:48 am

Hello,

Thanks for your following up.
Sorry there is no significant progress yet, please spare us more time. I will let you know if there any update. Thanks for your understanding.

Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Return to Spire.PDF

cron