Link
Skip to main content

Prevent JVM crash when converting PDF to image

Sometimes when you try and convert a very large PDF to image, the following error occurs:

java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75)
at java.awt.image.Raster.createPackedRaster(Raster.java:467)

This means that Java is unable to allocate memory for the image you are trying to create an image of the current PDF page.

The JVM cannot handle a BufferedImage over a certain size (the exact amount is system dependent). Increasing the heap size may help but does not fix all memory issues in Java (especially when they involve both Java and Native heap).

Another solution is to covert the PDF at a smaller scaling. For example, you can create scaled images using ConvertPagesToImages as described in the Javadoc examples.

You could also use the getPageDimensions to check the page size before conversion to test if the document is too large for your system to handle then produce the page at a smaller size.


Why JPedal?

  • Actively developed commercial library with full support and no third party dependencies.
  • Process PDF files up to 3x faster than alternative Java PDF libraries.
  • Simple licensing options and source code access for OEM users.

Learn more about JPedal

Start Your Free Trial


Customer Downloads

Select Download