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

Free Support Forum - aspose.com

PngDevice - How to Configure

Hi, I am processing a wide variety of PDFs in my application. I convert each PDF into individual PNGs and then display those PNGs in a web page for the user to view.

I am dealing with light-weight PDFs, typically converted from Word documents, and also heavy weight PDFs, typically scanned at high dpi or derived from complex diagrams.

My output is always an image that matches the ratio aspect of the PDF page, should be clear to read and not too many KB (up to max 300KB, more usually 70KB).

I am trying to understand the different options on the PngDevice class, but I cannot find any descriptive documentation. For example, I know that I can set the height, width and resolution in the PngDevice instance and the various booleans in the Rendering Options. My challenge is to navigate these settings to get an optimal result.

Is there any documentation available for these options, especially the ones in the rendering options?


Would you please explain a bit more about the results that you want to obtain using PngDevice. Please share a sample PDF and desired output PNG that you are unable to get using the API. We will investigate the scenario in our environment and share our feedback with you accordingly.

I think I have my strategy in place now as follows:

  1. Extract JPEGs, not PNGs, because they are smaller for large images, by roughly 50%
  2. If the PDf page has no text and only one image, then extract the image directly instead of using a jpegDevice.

This is a nice solution for the heavier PDFs that come into our system.


You can determine whether a PDF contains only text or images and extract images using following code snippet:

Document pdf = new Document(dataDir + "Rijksdienst voor Oudheidkundig Bodemonderzoek; Kerkstraat 1, Amersfoort - hires.pdf");
int index = 0;
foreach (Page page in pdf.Pages)
 ImagePlacementAbsorber imagePlacementAbsorber = new ImagePlacementAbsorber();
 foreach (ImagePlacement imagePlacement in imagePlacementAbsorber.ImagePlacements)
  // Get the image using ImagePlacement object
  XImage image = imagePlacement.Image;
  string outputFileName = dataDir + "img_" + index + ".jpg";
  FileStream fs = new FileStream(outputFileName, FileMode.OpenOrCreate);
  image.Save(fs, 300);
  index += 1;