OutOfMemory Error occurs on generating PNG image of excel range


I am using Aspose.Cells v18.8 to generate PNG of range - “A1:L185” in the attached excel file. Following error occurs when generating the PNG:

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.za.(Unknown Source)
at com.aspose.cells.a.d.zcd.a(Unknown Source)
at com.aspose.cells.zcau.a(Unknown Source)
at com.aspose.cells.zcau.a(Unknown Source)
at com.aspose.cells.zcau.a(Unknown Source)
at com.aspose.cells.SheetRender.toImage(Unknown Source)

PFA below the source excel and sample code to generate the PNG:
attachments.zip (26.4 KB)

Can you please analyze this issue.



We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSJAVA-42730 - Exception java.lang.OutOfMemoryError: Java heap space


We have evaluated your issue further. We found the output area is large and the horizontal/vertical resolution is set to 600 which is quite high, so, the output image size will be 7413x100119. The exception is occurred while creating java.awt.BufferedImage with that size(7413x100119).

Please decrease the image dimensions. e.g. set horizontal/vertical Resolution to 96, it works fine as we tested:
Sample code:



Thanks for your reply.

We use horizontal/vertical resolution 600 for all the chart or table or range images we generate and they all work fine except for this particular case.

We cannot change the resolution dynamically on a case by case basis. We have been using Aspose.Cells since so many years and have never faced this issue before.

Can you please look into this issue and provide a resolution for this.



Thank you for contacting us again. We have logged this concern with the ticket and will write back once any update is ready to provide here.


As we said in the last comment, the image dimension is 7413 x 100119, so its memory size will be 7413 x 100119 X4 bytes (about 2800MB).

You can try the following resolutions as we cannot fix it:

  1. Give more memory: on our side, when we are trying to give 6g memory (-Xmx6g), the image is generated successfully.
  2. Try to reduce the print area if possible.


Thanks for your response. However, I feel that increasing memory and reducing print area will not provide the permanent resolution. As after increasing the memory, one may encounter documents which may require even beyond 6GB …

Since such kind of documents stops the complete Java process in production environment, is there any alternate way to get rid of such situations.

Does Aspose provide any guidelines or prevention mechanism which can be used before actually generating the document object of the complete excel file?

Can you please consider this on priority basis as this is very genuine problem and being faced by our customers in their production environment.



Such issues are difficult to cope with. Could you try using our latest version/fix: Aspose.Cells for Java v19.4.x if it makes any difference.

Aspose.Cells does have a mechanism of interrupting process, see the document with example code if it suits your needs for your reference:
Stop conversion or loading using InterruptMonitor when it is taking too long

If you still find the issue and you are using different samples or scenario, kindly do provide your sample code and template files, we will check it soon.


Also, SheetRender.getPageSize(int pageIndex) API can get the page size in points. This may be helpful to determine whether to generate the output image or not.