Free Support Forum - aspose.com

Out of memory exceptions when converting images to pdf

We are receiving a “java.lang.OutOfMemoryError” during the final save of a PDF after converting certain image files to PDF. Below is the section of code.

    if(chunkCount > 0) {
        result = getResultTarget(ZIP_FORMAT);
        try (OutputStream output = result.getOutputStream()){
            saveAndClearPdf();
            stitchAndCleanChunks(output);
        }
    } else {
        result = getResultTarget(PDF_FORMAT);
        try (OutputStream output = result.getOutputStream()){
            pdf.optimize();
            pdf.optimizeResources(getOptimizationOptions());
            LOGGER.debug("Saving final PDF");
            pdf.save(output);
        }

seb-softmed-18337209-REDACT.zip (240.5 KB)

This is one of the images

@BobScottHSHS,

I have observed the issue shared by you and request you to please provide information about which version of Aspose.Imaging you have used on your end along with Java and Operating System details. I also suggest you to please consider increasing the Java heap size as well on your end to see if the issue persist or not.

We are running the Aspose Total which contains the Aspose.PDF 19.10 and Aspose Imaging 19.11. We have also attempted to incorporate Aspose Imaging 20.3 and received the same results.

The environment is Windows 2016 with Java 8 Update 181.

What would you recommend we increase the heap size to?

@BobScottHSHS,

In my humble suggestion, you may first try to use Aspose.Imaging for Java in a separate application and perform your rendering. We cannot suggest you a heap size as it depends on your machine configurations and type of file used. You may try setting heap size of 4GB or more.

I will attempt in a separate application. In the meantime, did you also attempt to convert the image I uploaded in your system?

@BobScottHSHS,

I request you to please share the working sample code that you have used on your end to reproduce the issue and I will try the same on my end too.