Aspose Cdr to Pdf convertion Heap Error

type or paste code here
This is my Java code to convert CDR file into PDF file 
this throw heap error 



package Activation;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import com.aspose.imaging.Image;
import com.aspose.imaging.fileformats.cdr.CdrImage;
import com.aspose.imaging.imageoptions.PdfOptions;

import code.Main_Frame;
import code.ency;

public class TestPdf {
    public static void main(String[] args) {
    	try {
			InputStream is = Main_Frame.class.getResourceAsStream("/data.txt");
			byte[] buff = new byte[is.available()];
			is.read(buff);
			ency td = new ency();
			String decrpt = td.decrypt(buff);
			OutputStream outStream = new FileOutputStream(
					System.getProperty("java.io.tmpdir") + File.separator + "Email.txt");
			outStream.write(decrpt.getBytes());
			is.close();
			outStream.flush();
			outStream.close();
			File file = new File(System.getProperty("java.io.tmpdir") + File.separator + "Email.txt");
			if (file.exists()) {
				com.aspose.imaging.License lic_img = new com.aspose.imaging.License();
				com.aspose.pdf.License lic_pdf = new com.aspose.pdf.License();
				lic_img.setLicense(file.getPath());
				lic_pdf.setLicense(file.getPath());
				file.delete();
			}
			file = new File(System.getProperty("java.io.tmpdir") + File.separator + "Email.txt");
			if (file.exists()) {
				file.delete();
			}
		} catch (Exception e1) {
			e1.printStackTrace();
		}
        // Path to the input CDR file
        String inputFile = "C:\\Users\\Aryson\\Downloads\\Holy Snake d.cdr";
        // Path to the output PDF file
        String outputFile = "C:\\\\Users\\\\Aryson\\\\Downloads\\\\Holy Snake d.pdf";

        // Load the CDR file
        try (CdrImage cdrImage = (CdrImage) Image.load(inputFile)) {
            // Create PDF options
            PdfOptions pdfOptions = new PdfOptions();
            // Save the CDR file as PDF
            cdrImage.save(outputFile, pdfOptions);
            System.out.println("CDR file converted to PDF successfully!");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

@asheesh.patel

It seems you are encountering a heap error while trying to convert a CDR file to a PDF using Aspose.Imaging in Java. This type of error often occurs when the Java Virtual Machine (JVM) runs out of memory during the execution of your program, especially when dealing with large files or images.

To address this issue, you can try the following steps:

  1. Increase JVM Heap Size: You can increase the maximum heap size allocated to the JVM by using the -Xmx option. For example, you can set it to 2GB by adding the following to your Java command:

    java -Xmx2g -jar your-application.jar
    
  2. Use Rasterization Options: When converting CDR files, it is beneficial to use rasterization options to manage memory usage better. Here’s an example of how to implement this in your code:

    import com.aspose.imaging.Image;
    import com.aspose.imaging.fileformats.cdr.CdrRasterizationOptions;
    import com.aspose.imaging.imageoptions.PdfOptions;
    import com.aspose.imaging.imageoptions.VectorRasterizationOptions;
    
    public void exportToPdf(String inputCdrFileName, String outputPdfFileName) {
        try (Image image = Image.load(inputCdrFileName)) {
            PdfOptions pdfOptions = new PdfOptions();
            CdrRasterizationOptions rasterizationOptions = new CdrRasterizationOptions();
            rasterizationOptions.setTextRenderingHint(TextRenderingHint.SingleBitPerPixel);
            rasterizationOptions.setSmoothingMode(SmoothingMode.None);
            rasterizationOptions.setPositioning(PositioningTypes.DefinedByDocument);
            pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
            image.save(outputPdfFileName, pdfOptions);
        }
    }
    
  3. Check for Memory Leaks: Ensure that your application is not holding onto references of large objects longer than necessary, which can lead to memory exhaustion.

  4. Test with Smaller Files: If possible, test your conversion process with smaller CDR files to see if the issue persists. This can help determine if the problem is related to file size.

If you continue to experience issues, consider checking the Aspose support forums for similar cases or reporting the problem with details about the specific CDR file you are using, as there may be known issues with certain file types.

By following these suggestions, you should be able to mitigate the heap error and successfully convert your CDR files to PDF.

Sources:
[1]: CDR (Coral draw) to PDF conversion (Java)

ok but in windows machine we can easily increase the memory size or heap size in jar and as well as .exe it run always as per you given documentation.
but in mac we can not increase heap size or memory on Mac Machine because mac os did not provide explicit memory in .dmg(executable file on mac os).
now what can i do?

class com.aspose.imaging.coreexceptions.ImageSaveException: Image export failed. —> class com.aspose.imaging.internal.Exceptions.ArgumentException: com.aspose.imaging.internal.jW.j : com.aspose.imaging.internal.jW.j : com.aspose.imaging.internal.jW.j : com.aspose.imaging.internal.jW.j : com.aspose.imaging.internal.jW.j : com.aspose.imaging.internal.jW.j : com.aspose.imaging.internal.jW.j : com.aspose.imaging.internal.jW.j : com.aspose.imaging.internal.jW.x : Java heap space[ java.util.ArrayList.iterator
1029 in ArrayList.java
java.io.InputStream.readNBytes

Hi @asheesh.patel

Please review the response in this thread. It seems that the threads are duplicating each other.

@Nikita_Romanov
i implement loading option
com.aspose.imaging.LoadOptions loadOptions = new com.aspose.imaging.LoadOptions();
loadOptions.setBufferSizeHint(300);
and sets the bufferSizeHint
but this also throw the heap error during convertion in mac machine
and the cdr file size is only 220 MB .how and why aspose api can not handle the heap error
on just 220MB cdr file.
i already purchase the aspose family Api plan.

The sample code is same as mac machine only path is different on mac machine

package Activation;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import com.aspose.imaging.Image;
import com.aspose.imaging.SmoothingMode;
import com.aspose.imaging.TextRenderingHint;
import com.aspose.imaging.fileformats.cdr.CdrImage;
import com.aspose.imaging.imageoptions.PdfOptions;
import com.aspose.imaging.imageoptions.PositioningTypes;
import com.aspose.imaging.imageoptions.CdrRasterizationOptions;
import com.aspose.imaging.imageoptions.*;
import code.Main_Frame;
import code.ency;

public class TestPdf {
public static void main(String[] args) {
try {
InputStream is = Main_Frame.class.getResourceAsStream(“/data.txt”);
byte[] buff = new byte[is.available()];
is.read(buff);
ency td = new ency();
String decrpt = td.decrypt(buff);
OutputStream outStream = new FileOutputStream(
System.getProperty(“java.io.tmpdir”) + File.separator + “Email.txt”);
outStream.write(decrpt.getBytes());
is.close();
outStream.flush();
outStream.close();
File file = new File(System.getProperty(“java.io.tmpdir”) + File.separator + “Email.txt”);
if (file.exists()) {
com.aspose.imaging.License lic_img = new com.aspose.imaging.License();
com.aspose.pdf.License lic_pdf = new com.aspose.pdf.License();
lic_img.setLicense(file.getPath());
lic_pdf.setLicense(file.getPath());
file.delete();
}
file = new File(System.getProperty(“java.io.tmpdir”) + File.separator + “Email.txt”);
if (file.exists()) {
file.delete();
}
} catch (Exception e1) {
e1.printStackTrace();
}
// Path to the input CDR file
String inputFile = “C:\Users\Aryson\Downloads\Holy Snake d.cdr”;
// Path to the output PDF file
String outputFile = “C:\\Users\\Aryson\\Downloads\\Holy Snake d.pdf”;

    // Load the CDR file
    com.aspose.imaging.LoadOptions loadOptions = new com.aspose.imaging.LoadOptions();
    loadOptions.setBufferSizeHint(300); 
    try (CdrImage cdrImage = (CdrImage) Image.load(inputFile)) {
        // Create PDF options
    	PdfOptions pdfOptions = new PdfOptions();
        CdrRasterizationOptions rasterizationOptions = new CdrRasterizationOptions();
        rasterizationOptions.setTextRenderingHint(TextRenderingHint.SingleBitPerPixel);
        rasterizationOptions.setSmoothingMode(SmoothingMode.None);
        rasterizationOptions.setPositioning(PositioningTypes.DefinedByDocument);
        pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
        // Save the CDR file as PDF
        cdrImage.save(outputFile, pdfOptions);
        System.out.println("CDR file converted to PDF successfully!");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

Hello, @asheesh.patel
We will analyze this issue ASAP.
We regret that you faced the issue. :frowning:

Hello, @asheesh.patel
Could you provide us with your test file?

Yes, I have attached the CDR file; the link is provided below. I hope this helps you resolve the issue. Please ensure the confidentiality and integrity of the file.
CDR file that creates heap error on mac/window

@asheesh.patel , we will review your attachment and give a feedback shortly!

Hello, @asheesh.patel
We discovered that using 3Gb of memory solves this issue

java -Xmx3g -jar your-application.jar

However, we will find out why we need so much memory.

Ok, I can increase the memory in Windows OS, but when I use this on macOS, it does not provide any extra memory to the DMG

Understood, we are looking for a way to minimize this requirement.