Get X/Y Position of Image in PDF in C#, VB.NET

The following code snippets show you how we can find x and y coordinates of an image in a PDF document.

Step 1: Create a PdfDocument object and load a sample PDF file.

PdfDocument doc = new PdfDocument();
doc.LoadFromFile("sample.pdf");

Step 2: Get all the image information from the specified page.

PdfImageInfo[] imageInfo = doc.Pages[0].ImagesInfo;

Step 3: Get the x and y coordinates of the first image through Bounds property.

RectangleF rect = imageInfo[0].Bounds;
Console.WriteLine("The image is located at({0},{1})", rect.X, rect.Y);

Output:

How to Get X/Y Position of Image in PDF in C#, VB.NET

Full Code:

[C#]
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("sample.pdf");
PdfImageInfo[] imageInfo = doc.Pages[0].ImagesInfo;
RectangleF rect = imageInfo[0].Bounds;
Console.WriteLine("The image is located at({0},{1})", rect.X, rect.Y);
[VB.NET]
Dim doc As PdfDocument = New PdfDocument()
doc.LoadFromFile("sample.pdf")
Dim imageInfo As PdfImageInfo() = doc.Pages(0).ImagesInfo
Dim rect As RectangleF = imageInfo(0).Bounds
Console.WriteLine("The image is located at({0},{1})", rect.X, rect.Y)