Aspose.PDF "doc.OptimizeResources()" throws "Out of Memory" exception?

Hi,

We are trying replace our “QuickPDF” component with “Aspose.PDF”.

We found another issue when we call OptimizeResources() function of Document object. Below is the code that we are using.

private void OptimizeDocument(Document documentToOptimize)
{
documentToOptimize.ProcessParagraphs();
Aspose.Pdf.Optimization.OptimizationOptions options = new Aspose.Pdf.Optimization.OptimizationOptions()
{
LinkDuplcateStreams = true,
RemoveUnusedObjects = true,
AllowReusePageContent = true,
RemoveUnusedStreams = true,
UnembedFonts = false,
};

        options.ImageCompressionOptions.CompressImages = true;
        options.ImageCompressionOptions.ImageQuality = 100;// Should be 100 always else affects images appearance.
        options.ImageCompressionOptions.ResizeImages = true;
        documentToOptimize.OptimizeResources(options);
    }

Below is the screen shot of stack trace.
stack trace Screenshot (216).png (261.1 KB)

I believe our production application where we merge 1500 pdf pages, throws this exception when it crosses 1.2GB of memory usage, so in order to replicate this you just need to increase the number of files to merge(may be >5k) and call the “OptimizeDocument” function later.

Also, we have observed a sudden spike in memory from 300MB to 1.2GB when this function is called.

Update: We are getting another exception some of the times (refer below screenshot).
Screenshot (218).png (220.4 KB)

Please review and provide us a solution as soon as you can.

Thanks,
Prathap

@PrathapSV

Could you please attach the following resources here for testing:

  • Your input PDF.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Hi,

Since we were getting “Out of memory exception” from Aspose library (version 17.8.0.0), we have upgraded the library to the latest version (#region Assembly Aspose.PDF, Version=22.4.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56) and we still get the same “Out of memory exception” exception.

Details:


As per our analysis, the exception occurs when there are more than 15 pages for pdf conversion. Also, it comes from below method call

Aspose.Pdf.Document.Save(string outputFileName) from Aspose.Pdf namespace.

Exception:


System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown.

Please review and provide your feedback as soon as possible.

@tjeganathan

Can you provide the file with which the problem occurs? This is necessary so that we can reproduce and analyze the problem.

@sergei.shibanov, It is a TIFF format file and unable to upload here.

@tjeganathan
Are you using the code you provided with the pdf file? Then i need a pdf to reproduce.

@sergei.shibanov, We create pdf file using Aspose library, from the scanned file (TIFF format) and the scanned TIFF file into pdf conversion is failing and prompted with above mentioned Out of memory exception. Hence we are not able to generate the pdf file. Can we get into a call to sort out this issue immediately?

@tjeganathan
Neither the topic title nor the code above is intended to convert tiff to pdf. Judging by them, work is being done with a pdf document, which is why we asked for a pdf document.

For issue about create a pdf file using a library from a scanned file (TIFF format), it is better to create a separate branch in which to bring the code fragment used and attach the tiff file. You can zip it into a zip archive - embed such files is possible. Another option (especially if you can’t attach it because of the size) is to upload the file to the cloud and give a link.