Heap error during CDR to Pdf convertion

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();
        }
    }
}

@satvikverma7956

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 application runs out of memory, especially when dealing with large files or images.

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

  1. Increase Java Heap Size: You can increase the maximum heap size allocated to the Java Virtual Machine (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.imageoptions.CdrRasterizationOptions;
    import com.aspose.imaging.imageoptions.PdfOptions;
    import com.aspose.imaging.Image;
    
    // Load the CDR file
    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();
    }
    
  3. Check for Updates: Ensure you are using the latest version of Aspose.Imaging, as updates may include performance improvements and bug fixes that could resolve your issue.

  4. Monitor Memory Usage: Use profiling tools to monitor memory usage during the conversion process. This can help identify if there are specific points where memory spikes occur.

If the problem persists after trying these suggestions, it may be beneficial to check the Aspose support forums or documentation for any known issues related to the specific CDR file you are working with, as there have been reports of similar issues in the past.

Feel free to reach out if you need further assistance!

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

it works on window because we can give the extra memory in window os and exe as well
but mac os did not provide the extra memory to dmg .
exception found in mac machine
my mac configuration is M3 processor
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

Hello @satvikverma7956
Thank you for the provided details.
Please try to use the memory safe mechanism by using setBufferHint.

// if you wish set the limit for all images, please use
com.aspose.imaging.memorymanagement.setBufferSizeHint(300/*MB limit*/);
// otherwise use LoadOptions.setBufferHint(300); for each new image by this way
LoadOptions loadOptions = new LoadOptions();
loadOptions.setBufferHint(300); // 300 MB limit for pixel&vector data storages
try (CdrImage cdrImage = (CdrImage) Image.load(inputFile, loadOptions)) {
.....