We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Convert Tiff to PDF in java | memory leak in Aspose PDF 21.5

Hello,

We are converting Tiff images to pdf using Aspose PDF Java 21.5 and noticed that there appears to be a memory leak because we get an out of memory exception. If I run the follow code snippet below with a tiff images 1000 times to simulate a 1,000 page document it runs out of memory.

BufferedImage image = ImageIO.read(new File(inputFilePath));
        
 boolean rotateToLandscape = image.getWidth() > image.getHeight();

    Document doc = new Document();
    Page page = doc.getPages().add();

    if (rotateToLandscape) {
        page.getPageInfo().setLandscape(true);
    }

    com.aspose.pdf.Image image1 = new com.aspose.pdf.Image();
    image1.setBufferedImage(image);
    page.getParagraphs().add(image1);

    page.getPageInfo().getMargin().setBottom(0);
    page.getPageInfo().getMargin().setTop(0);
    page.getPageInfo().getMargin().setLeft(0);
    page.getPageInfo().getMargin().setRight(0);

    doc.save(outputFilePath);

Error: java.lang.OutOfMemoryError: Java heap space

@nduncanEpiq

Can you please share the source TIFF file so that we may try to reproduce the same on our end.

@mudassir.fayyaz,

I’ve uploaded the file to https://imgur.com/a/Q9fDkco. However, the error is not specific to a particular tiff file. You can reproduce it with any tiff converting the file 1k, 5k, or 10k times.

@nduncanEpiq

I have been able to reproduce the issue on our end. A ticket with ID PDFJAVA-40715 has been created in our issue tracking system to further investigate the issue on our end. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

1 Like