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

Free Support Forum - aspose.com

Out of memory issue when saving as JPEG

Hi,

I'm getting the out of memory exception when trying to save an Excel sheet as JPEG:

This is the code I use:

ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.setImageFormat(ImageFormat.getJpeg());
imgOptions.setOnePagePerSheet(true);
imgOptions.setHorizontalResolution(300);
imgOptions.setVerticalResolution(300);
imgOptions.setCellAutoFit(true);
imgOptions.setQuality(100);
//Render the sheet with respect to specified image/print options
SheetRender sr = new SheetRender(doc.getWorksheets().get(0), imgOptions);
//Render the image for the sheet
sr.toImage(0, jpegFile.getAbsolutePath());

This is the exception I get every time:

java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferInt.(DataBufferInt.java:41)
at java.awt.image.Raster.createPackedRaster(Raster.java:458)
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1015)
at java.awt.image.BufferedImage.(BufferedImage.java:312)
at com.aspose.cells.b.a.b.a.(Unknown Source)
at com.aspose.cells.a.d.bm.a(Unknown Source)
at com.aspose.cells.bgp.a(Unknown Source)
at com.aspose.cells.bgp.a(Unknown Source)
at com.aspose.cells.SheetRender.toImage(Unknown Source)


My memory settings are as follows:
-Xrs -Xmx768M -Xss4096K -XX:MaxPermSize=512m
I'm attaching the file that fails. I'm using version 8.0.0

Thanks in advance for any help,
Mariusz

Hi Mariusz,

Thanks for your posting and using Aspose.Cells.

We were able to observe this exception after running the following code with your source xlsx file using the latest version: Aspose.Cells
for Java v8.1.0.3
.

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once, the issue is resolved or we have some other update for you, we will let you know asap

This issue has been logged as CELLSJAVA-40871.

Java


String filePath = “F:\Shak-Data-RW\Downloads\worksheet+functions.xlsx”;


Workbook doc = new Workbook(filePath);


ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

imgOptions.setImageFormat(ImageFormat.getJpeg());

imgOptions.setOnePagePerSheet(true);

imgOptions.setHorizontalResolution(300);

imgOptions.setVerticalResolution(300);

imgOptions.setCellAutoFit(true);

imgOptions.setQuality(100);

//Render the sheet with respect to specified image/print options

SheetRender sr = new SheetRender(doc.getWorksheets().get(0), imgOptions);

//Render the image for the sheet

sr.toImage(0, filePath + “.out.jpg”);
Exception:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferInt.(Unknown Source)
at java.awt.image.Raster.createPackedRaster(Unknown Source)
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
at java.awt.image.BufferedImage.(Unknown Source)
at com.aspose.cells.b.a.b.a.(Unknown Source)
at com.aspose.cells.a.d.bm.a(Unknown Source)
at com.aspose.cells.bgt.a(Unknown Source)
at com.aspose.cells.bgt.a(Unknown Source)
at com.aspose.cells.bgt.a(Unknown Source)
at com.aspose.cells.SheetRender.toImage(Unknown Source)
at ClsAsposeTest.f1(ClsAsposeTest.java:325)
at ClsAsposeTest.main(ClsAsposeTest.java:33)

Hi Mariusz,

Thanks for using Aspose.Cells.

We have evaluated this issue further. The sheet of the your Excel file has many rows. And since “OnePagePerSheet”
is set, so the generated image is large. We need more memory to generate the image.


Just extend Java vm heap: e.g. -Xmx2048M