Free Support Forum - aspose.com

How to get the resolution of pdf?

Hi, Support:

Is there any method to get the resolution of pdf? or get the resolution of each image in the pdf?

@ducaisoft

There is no method to determine resolution of the PDF as PDF documents are DPI independant and it depends upon the device where they are going to render. However, you can extract different properties of images inside PDF such as resolution. Please consider using following code snippet:

// Open document
Document document = new Document(dataDir + "Test.pdf");

// Create ImagePlacementAbsorber object to perform image placement search
ImagePlacementAbsorber abs = new ImagePlacementAbsorber();

// Accept the absorber for first page
document.getPages().accept(abs);

// Display image placement properties for all placements
for (Object imagePlacement : abs.getImagePlacements())
{     
    ImagePlacement placement = (ImagePlacement) imagePlacement;
    System.out.println("image width:" + placement.getRectangle().getWidth());
    System.out.println("image height:" + placement.getRectangle().getHeight());
    System.out.println("image horizontal resolution:" + placement.getResolution().getX());
    System.out.println("image vertical resolution:" + placement.getResolution().getY());
}