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

Free Support Forum - aspose.com

Get image coordinates from pdf

Hi,

I am trying to find a way to get the coordinates of an image from the pdf but i did not see that function in the library.
Can you help me with it?

The way i got the image is
XImage xImage = doc.getPages().get_Item(1).getResources().getImages().get_Item(1);

Thank you

Hi Jun,


Thanks for your inquiry.

You can use ImagePlacementAbsorber to extract ImagePlacement from PDF document and get rectangle of the images later. Please check following code snippet, in order to achieve that.

Document
doc = new Document(dataDir + “input.pdf”);<o:p></o:p>

ImagePlacementAbsorber abs = new ImagePlacementAbsorber();

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

for(int i = 1;i <= abs.getImagePlacements().size();i++)

{

ImagePlacement image = abs.getImagePlacements().get_Item(i);

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

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

System.out.println("URX : " + image.getRectangle().getURX());

System.out.println("URY : " + image.getRectangle().getURY());

}



In case in you face any issue, please share your input document, so that we can test the scenario in our environment and address it accordingly.


Best Regards,