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.

Mon Jun 20, 2022 8:19 am

Hello
using the "standard" code to optimize images
Code: Select all
      PdfPageCollection pages = document.getPages();
      for (int i = 0; i < pages.getCount(); i++) {
         PdfPageBase page = pages.get(i);
         if (page != null) {
            PdfImageInfo[] infos = page.getImagesInfo();
            if (infos != null) {
               for (PdfImageInfo pdfImageInfo : infos) {
                  page.tryCompressImage(pdfImageInfo.getIndex());
               }
            }
         }
      }


I get an OutOfMemory exception when using some files with a lot of images.
The runtime also increase in a clearly non-linear fashion...

Thanks in advance
Guillaume PATRY

GuiPATRY
 
Posts: 37
Joined: Wed Feb 17, 2021 10:18 am

Mon Jun 20, 2022 10:04 am

Hello Guillaume,

Thanks for your inquiry.

Parsing and processing images will take a lot of resources. I suggest that you first try to increase the maximum memory limit of the JVM so that the program has more resources to use and thus reduce the situation of insufficient memory. If the issue still exists, could you please provide us with some test pdfs to help us better investigate and optimize this issue? Thanks in advance for your assistance.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Return to Spire.PDF