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.

Thu Mar 04, 2021 3:41 am

Hi,
I am testing out the product using the Free Spire.PDF for .Net Core.
Is there a limitation enforced for the PDF compression?
I have problem compressing a 2 pages PDF that was a scanned document.
The compression process does not complete until out-memory.
If I split doc to single pages, the compression works.

hcchoi66
 
Posts: 1
Joined: Thu Mar 04, 2021 2:55 am

Thu Mar 04, 2021 7:26 am

Hello,

Thanks for your inquiry!

Kindly note that our Free Spire.PDF is limited to 10 pages of PDF, and this limitation is enforced during loading and creating files.

I used the following code to compress a scanned PDF document with 2 pages with the latest Free Spire.PDF V7.2 in .Net Core 3.1, but did not reproduce your issue.
Code: Select all
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(@"E:\testdoc\Sample.pdf");

            CompressContent(doc);

            CompressImage(doc);

            doc.SaveToFile("CompressDocument_result.pdf");

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

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

        private 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);
                        }
                        foreach (PdfImageInfo info in page.ImagesInfo)
                        {
                            info.Image.Dispose();
                        }
                    }
                }
            }
        }


To help us further investigate and reproduce your issue, please provide us with your input file and testing code for reference, you can send them to us via email ([email protected]). Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Mon Mar 22, 2021 8:16 am

Hello,

Hope you are doing well!

How is the issue now? If it still exists, could you please provide your input file and testing code to us for further investigation? You can send them to us via email ([email protected]).

Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Return to Spire.PDF