Aspose.PDF: Word and image coordinate sample code

Hi,

I am trying to see if I can get the exact spatial coordinates, on the PDF page, of a particular word. I need to map the position of a word on the PDF page with the same word on the image of the page. I am trying to highlight a words as they are read, on the TIFF image of the PDF page. To do that, I need the coordinates of the word from the PDF page.

I've looked at the Aspose.PDF.Text namespace's Position class, but did not find and samply code with it.

Can you please provide me a sample that allows me to determine the exact coordinates of a word on the PDF page?

Can I also get the coordinates of an image?

Thank you,

Saif Faruqui

Hi Saif,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for using our product.

As per your requirements, you can use ImagePlacementAbsorber and TextFragmentAbsorber classes to get image coordinates and text coordinates respectively. Please see the following documentation links for more details and sample code regarding TextFragmentAbsorber.

Search and Get Text from All the Pages of PDF Document

You may check the following sample code regarding ImagePlacementAbsorber.

// Open document

Document doc = new Document(@"D:\Tests\input.pdf");

// Create ImagePlacementAbsorber object to perform image placement search

ImagePlacementAbsorber abs = new ImagePlacementAbsorber();

// Accept the absorber for first page

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

// Display image placement properties for all placements

foreach (ImagePlacement imagePlacement in abs.ImagePlacements)

{

Console.Out.WriteLine("image width:" + imagePlacement.Rectangle.Width);

Console.Out.WriteLine("image height:" + imagePlacement.Rectangle.Height);

Console.Out.WriteLine("image LLX:" + imagePlacement.Rectangle.LLX);

Console.Out.WriteLine("image LLY:" + imagePlacement.Rectangle.LLY);

Console.Out.WriteLine("image horizontal resolution:" + imagePlacement.Resolution.X);

Console.Out.WriteLine("image vertical resolution:" + imagePlacement.Resolution.Y);

}

Please feel free to contact support in case you need any further assistance.

Sorry for the inconvenience,

Using the above code how to search for a text in the image of pdf. I mean to say i have converted pdf which has an image in it and i need search for a text in that pdf. How do i do this using ImagePlacementAbsorber

@pradeepdone

Please note that ImagePlacementAbsorber class can be used to work with images in a PDF document, for example add, delete or extract images, which is not suitable for your scenario which you have mentioned in other thread. Therefore, please share requested data and follow up in respective thread so that we may assist you accordingly.