Get Coordinates of Images in PDF in Java

This article shows you how to get x and y coordinates of images in a PDF page by using Spire.PDF for Java.

import com.spire.pdf.exporting.PdfImageInfo;
import java.awt.geom.Rectangle2D;

public class GetCoordinateOfImage {

    public static void main(String[] args) {

        //Create a PdfDocument object
        PdfDocument doc = new PdfDocument();

        //Load a PDF file
        doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\Images.pdf");

        //Get the first worksheet
        PdfPageBase page = doc.getPages().get(0);

        //Get the image information of the page
        PdfImageInfo[] imageInfo = page.getImagesInfo();

        //Loop through the image information
        for (int i = 0; i < imageInfo.length; i++) {

            //Get the bounds property of a specific image
            Rectangle2D rect = imageInfo[i].getBounds();

            //Get the x and y coordinates
            System.out.println(String.format("The coordinate of image %d:(%f, %f)", i+1, rect.getX(), rect.getY()));
        }
    }
}

Get Coordinates of Images in PDF in Java