Free Support Forum - aspose.com

Calculate pdf page dpi or image dpi

Dear Aspose,

I want to know if the PDF file is composed of scanned images or electronically generated.
In order to do this, we decided to judge it as a scanned image document if the following conditions are satisfied.

  1. Each page of the PDF consists of one image
  2. The images are very similar to the size of the MediaBox.

Using this, we can see that the width and height of the XImage object can be obtained in pixels, and the width and height of the MediaBox can be obtained in point.
If the DPI is fixed (200 for example), it can be converted to (MediaBox.getWidth () / 72) * 200, but we could not find any clue to calculate it.

How can I get help to implement the idea above?

Thank you.

@troublecoder

Thank you for contacting support.

We would like to share with you that you can get the different properties, including resolution, of an image by using the code snippet below:

// 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());
}

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

Dear Farhan.Raza,

Thank you for your support!