Convert PDF to image[PNG] failure using pdfdraw

Product: Windows PDF library

Product Version:
com.pdftron
PDFNet
10.6.0

Please give a brief summary of your issue:
I am converting PDF to png image using below sample code

				draw.setDPI(2000);
				Page pg = doc.getPage(1);
				draw.export(pg, (sample.png));

Getting below exception:

{"com.pdftron.common.PDFNetException: Exception: \n\t Message: unable to allocate render buffer\n\t Conditional expression: _buf\n\t Version      : 10.6.0-5f8bfec\n\t Platform     : Linux\n\t Architecture : AMD64\n\t Filename     : PDFDraw.cpp\n\t Function     : AllocBuffer\n\t Linenumber   : 1244\n\n\tat com.pdftron.pdf.PDFDraw.Export(Native Method)\n\tat com.pdftron.pdf.PDFDraw.export(PDFDraw.java:463)\n\tat 

Ask here :

  1. It should not reduce the original resolution of the PDF once after converting to png
  2. Please help me out here to solve the exception.

Sample PDF file:
sample.pdf (32.5 KB)

1 Like

2000 DPI is very high, and since your PDF is over 8.2"x11.8" you are generating a 16,444x23,600px image, or a 388MegaPixel image. Compare to lastest highend iPhone camera which only takes 48MP images.

This is why you are exhausting the available memory.

Why is 2000 DPI important for you?
What do you do with the image afterwards?

It should not reduce the original resolution of the PDF once after converting to png

Strictly speaking PDF files have no “original” resolution, since it is a vector format, it can be any resolution you want. Only any images contained in the PDF have a resolution.

The DPI for a PDF is 72, but that is typically too low for an image DPI.

Please help me out here to solve the exception.

Decide on what resolution you do want, and use PDFDraw.SetImageSize instead of using DPI.

2 Likes