Memory Management

Hello,

We need ways to save and use less memory when converting files to PDF and printing PDF files.
We are using:

  • Aspose.CAD
  • Aspose.Cells
  • Aspose.Diagram
  • Aspose.Imaging
  • Aspose.Note
  • Aspose.PDF
  • Aspose.Slides
  • Aspose.Tasks
  • Aspose.Words

When using 1gb max memory on our java app printing a PDF file with 150 pages will cause an out of memory exception.

150 pages may seem large but we may be printing/converting multiple files at a time and want to avoid running out of memory.

Printing is done like this:

PdfPrinterSettings printerSettings = new PdfPrinterSettings();
printerSettings.setPrinterName(PRINTER_NAME);
printerSettings.setPrintToFile(true);
printerSettings.setPrintFileName(tempPrintFile);

PdfViewer viewer = new PdfViewer();
viewer.bindPdf(document);
viewer.setAutoResize(true);
viewer.setAutoRotate(true);
viewer.setPrintPageDialog(false);
viewer.setPrinterJobName(jobName);
	
viewer.printDocumentWithSettings(printerSettings);

Conversions to PDF are done like this (it is mostly the same for each Aspose library) :

    Image image = Image.load(inputStream);
	
	PdfOptions saveOptions = new PdfOptions();		

	image.save(Paths.get(TEMP_DIRECTORY, tempFileName).toString(), saveOptions);

@matthewanselmo

Thanks for your inquiry. Please note that the performance and memory usage all depend on the complexity and size of the documents you are generating.

Regarding Aspose.Words, you can set the value of SaveOptions.MemoryOptimization property to true for memory optimization. Setting this option to true can significantly decrease memory consumption while saving large documents at the cost of slower saving time.

Regarding Aspose.Slides, Aspose.CAD and Aspose.Imaging, the document is loaded in DOM and amount of memory consumed depends on file contents, size, number of slide & multimedia content (in case of Aspose.Slides). Secondly, during rendering process while exporting to PDF the excessive memory is required. Unfortunately, there is no benchmark memory requirement for this as it varies from case to case.

We will answer your query regarding other products shortly.

@matthewanselmo

For Aspose.Note, PDF can be converted as Flattened using NotebookPdfSaveOption by setting Flattern to true. In case of images, ImageCompression can be set to JPEG and JPEG Quality as well under PdfSaveOptions.

For Aspose.Cells, you may try MemorySetting.MemoryPreference option to optimize memory use for cells data and decrease the overall memory cost. Please read the following article.
Optimizing Memory Usage while Working with Big Files having Large Datasets

For Aspose.PDF, API does not include any property which can optimize or minimize memory usage while printing. Consumed memory varies based on specific PDF documents.

For Aspose.Diagram, a feature request for low memory consumption while converting to PDF has been logged as DIAGRAMJAVA-50625.