Free Support Forum - aspose.com

Image position on the page

Hello,

how to get the exact coordinates of image on the page?

Hi tomasz,


Thanks for your inquiry. Please check following code snippet to get image coordinates. Hopefully it will help you to accomplish your requirements.


// Open
document
<o:p></o:p>

Document doc = new Document(myDir+"input.pdf");

// Create ImagePlacementAbsorber object to perform image placement search

ImagePlacementAbsorber abs = new ImagePlacementAbsorber();

// Accept the absorber for first page

doc.getPages().get_Item(1).accept(abs);

// Display image placement properties for all placements

for (com.aspose.pdf.ImagePlacement imagePlacement : (Iterable)abs.getImagePlacements())

{

System.out.println("image width:" + imagePlacement.getRectangle().getWidth());

System.out.println("image height:" + imagePlacement.getRectangle().getHeight());

System.out.println("image LLX:" + imagePlacement.getRectangle().getLLX());

System.out.println("image LLY:" + imagePlacement.getRectangle().getLLY());

System.out.println("image horizontal resolution:" + imagePlacement.getResolution().getX());

System.out.println("image vertical resolution:" + imagePlacement.getResolution().getX());

}


Please feel free to contact us for any further assistance.


Best Regards,

Hi Tilal

I am getting error saying Aspose.Pdf.Document does not contain a defination for getPages and no extension method getPages accepting a first argument of type Aspose.Pdf.Document could be found.

Aspose.Pdf.Document doc = new Aspose.Pdf.Document(inFile);
Aspose.Pdf.ImagePlacementAbsorber abs = new Aspose.Pdf.ImagePlacementAbsorber();
doc.getPages().get_Item(1).accept(abs);

Help me on this. Thanks in advance.

@ajitboyite

Thanks for your inquiry.

By looking at the code snippet, that you have shared, it seems that you are using .NET library and trying to access the method with different syntax i.e. Java. Would you please confirm the API, which you are using in your environment. Just in case of .NET library, please use following code snippet:

doc.Pages[1].Accept(abs);

Thanks for the information :+1: