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:
Full Code:
[C#]
using Spire.Pdf; using Spire.Pdf.Exporting; using System; using System.Drawing; namespace Coordinates { class Program { static void Main(string[] args) { 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]
Imports Spire.Pdf Imports Spire.Pdf.Exporting Imports System.Drawing Namespace Coordinates Class Program Private Shared Sub Main(args As String()) Dim doc As 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) End Sub End Class End Namespace