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

Free Support Forum - aspose.com

java.lang.OutOfMemoryError: Java heap space

when i use aspose.cells,pdf,and so on for java to convert to image,when i used jdk1.7 it works ok,but when i use jdk1.6 execute it works error.for below:

Workbook excelDocument = new Workbook(System.getProperty(“user.dir”)
+ “\5.xlsx”);
com.aspose.cells.ImageOrPrintOptions imageOrPrintOptions = new com.aspose.cells.ImageOrPrintOptions();
imageOrPrintOptions.setOnePagePerSheet(true);
imageOrPrintOptions.setImageFormat(com.aspose.cells.ImageFormat
.getJpeg());
imageOrPrintOptions.setHorizontalResolution(100);
imageOrPrintOptions.setVerticalResolution(100);
com.aspose.cells.SheetRender sheetRender = new com.aspose.cells.SheetRender(
excelDocument.getWorksheets().get(0), imageOrPrintOptions);
try {
sheetRender.toImage(0, “5-1.jpeg”);
} catch (Exception exception) {
System.out.println(exception);
}



Exception in thread “main” 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.za.(Unknown Source)
at com.aspose.cells.a.d.zbm.a(Unknown Source)
at com.aspose.cells.zbip.a(Unknown Source)
at com.aspose.cells.zbip.a(Unknown Source)
at com.aspose.cells.SheetRender.toImage(Unknown Source)
at personal.lixp.demo.aspose.cells.MainTest.thumbnailTest(MainTest.java:51)
at personal.lixp.demo.aspose.cells.MainTest.main(MainTest.java:36)



com.aspose.pdf.devices.Resolution resolution = new com.aspose.pdf.devices.Resolution(
300);
com.aspose.pdf.devices.JpegDevice jpegDevice = new com.aspose.pdf.devices.JpegDevice(
resolution, 100);
jpegDevice.process(pdfDocument.getPages().get_Item(1),
outputStream);
outputStream.close();

it also works wrong when i use jdk 1.6,but our product use 1.6 How to do?? please solve it at once.

Hi Xu,


Thank you for contacting Aspose support.

We have evaluated your presented scenario in perspective of Aspose.Cells for Java API, and we are able to observe the OutOfMemoryError against the JDK revision 1,6.0_45 when maximum Java Heap size is set to 256M or low. However, increasing the maximum heap size to 512M or higher will let you avoid the said problem while exporting spreadsheets to image format. The VM arguments that will let you void the OutOfMemoryError for this case are: -Xms256M -Xmx512M.

Please also note that the process to render spreadsheets to images require more memory than rendering the spreadsheets to PDF format. Reason being, in order to render the spreadsheets to image formats, the Aspose.Cells APIs first create a Bitmap canvas (1881x16034 in this case) and then draw the contents over it. Therefore you should have sufficient memory to perform such operations especially when you have set the ImageOrPrintOptions.OnePagePerSheet property to true that forces the API to render all the contents of a given worksheet on a single image. Moreover, the latest JDK revisions as well as Aspose.Cells APIs have improved the memory utilization so it would be appropriate to upgrade the Aspose.Cells for Java API to the latest version 8.3.1.2 if you cannot upgrade the JDK in your environment.

We will shortly get back to you with updates regarding the other part of your inquiry (PDF to Image).

landray.com.cn:
when i use aspose.cells,pdf,and so on for java to convert to image,when i used jdk1.7 it works ok,but when i use jdk1.6 execute it works error.for below:

com.aspose.pdf.devices.Resolution resolution = new com.aspose.pdf.devices.Resolution(
300);
com.aspose.pdf.devices.JpegDevice jpegDevice = new com.aspose.pdf.devices.JpegDevice(
resolution, 100);
jpegDevice.process(pdfDocument.getPages().get_Item(1),
outputStream);
outputStream.close();

it also works wrong when i use jdk 1.6,but our product use 1.6 How to do?? please solve it at once.
Hi Xu,

Thanks for contacting support.

I have tested the scenario of PDF to Image conversion using Aspose.Pdf for Java 9.7.0 using jdk1.6.0_31 over Windows 7 (x64) and I am unable to notice any problem. For your reference, I have also attached the resultant JPEG generated over my end.

[Java]

com.aspose.pdf.Document pdfDocument = new
com.aspose.pdf.Document(“c:/pdftest/1.pdf”);<o:p></o:p>

com.aspose.pdf.devices.Resolution resolution = new com.aspose.pdf.devices.Resolution(300);

com.aspose.pdf.devices.JpegDevice jpegDevice = new com.aspose.pdf.devices.JpegDevice(resolution, 100);

jpegDevice.process(pdfDocument.getPages().get_Item(1),“c:/pdftest/1_Converted.jpg”);

when i execute it in main thread it works well,but when i execute it in a thread in thread pool,it throws the error.

Exception in thread “main” com.aspose.pdf.internal.p235.z115: FrameworkException: Not enough memory to process image.
at com.aspose.pdf.internal.p354.z42.m1(Unknown Source)
at com.aspose.pdf.internal.p354.z21.m1(Unknown Source)
at com.aspose.pdf.internal.p353.z1$z2.m1(Unknown Source)
at com.aspose.pdf.internal.p345.z49$z2.m1(Unknown Source)
at com.aspose.pdf.internal.p345.z43.m1(Unknown Source)
at com.aspose.pdf.internal.p345.z43.m1(Unknown Source)
at com.aspose.pdf.internal.p345.z49.m3(Unknown Source)
at com.aspose.pdf.internal.p345.z49.m1(Unknown Source)
at com.aspose.pdf.internal.p345.z49.m1(Unknown Source)
at com.aspose.pdf.internal.p345.z49.m1(Unknown Source)
at com.aspose.pdf.internal.p345.z49$z2.m1(Unknown Source)
at com.aspose.pdf.internal.p345.z43.m1(Unknown Source)
at com.aspose.pdf.internal.p345.z43.m1(Unknown Source)
at com.aspose.pdf.internal.p345.z49.m3(Unknown Source)
at com.aspose.pdf.internal.p345.z49.m1(Unknown Source)
at com.aspose.pdf.internal.p345.z49.m1(Unknown Source)
at com.aspose.pdf.internal.p345.z49.m1(Unknown Source)
at com.aspose.pdf.internal.p354.z25.m1(Unknown Source)
at com.aspose.pdf.internal.p381.z2.write(Unknown Source)
at javax.imageio.ImageWriter.write(ImageWriter.java:580)
at com.aspose.pdf.internal.p282.z1.m1(Unknown Source)
at com.aspose.pdf.internal.p282.z1.m2(Unknown Source)
at com.aspose.pdf.internal.p282.z1.m2(Unknown Source)
at com.aspose.pdf.internal.p282.z1.m1(Unknown Source)
at com.aspose.pdf.internal.p243.z2.m1(Unknown Source)
at com.aspose.pdf.internal.p243.z31.m1(Unknown Source)
at com.aspose.pdf.internal.p511.z11.m1(Unknown Source)
at com.aspose.pdf.devices.JpegDevice.processInternal(Unknown Source)
at com.aspose.pdf.devices.PageDevice.process(Unknown Source)
at com.landray.kmss.converter.office.AsposeOfficeToHTMLConverter.pdfToHTML(AsposeOfficeToHTMLConverter.java:382)
at (bolder class is a thread)com.landray.kmss.converter.office.AsposeOfficeToHTMLConverter.officeToHTML(AsposeOfficeToHTMLConverter.java:46)
at com.landray.kmss.converter.office.AsposeOfficeToHTMLConverter.execute(AsposeOfficeToHTMLConverter.java:32)
at com.landray.kmss.converter.test.MainTest.localPdfTest(MainTest.java:59)
at com.landray.kmss.converter.test.MainTest.main(MainTest.java:17)
Caused by: java.lang.OutOfMemoryError: Java heap space

Hi Xu,


Thanks for sharing the updates.

In order to replicate this issue in our environment, we request you to please share the code snippet. We are sorry for this inconvenience.