Need coordinate of a text on a PDF page

Hello
We have a site business license for Aspose,Total product
And we need help answering a few questions.

Right now we are marking certain spot in a PDF document with a placemarker string.

  1. We need to get the coordinates on the page of that place marker string.
  2. Once we got the coordinates … we need to be able to remove that placemarker string with blank.

We have been using CustomAsposeReplaceEvaluator object available in Aspose,Word product to do this.
However, for another scenario we do not have the Docx document to work with so we cannot use Aspose.Word to do the coordinate extraction and text replace operation.

We instead have a PDF document. And we would need to do the same using PDF instead of Docx

Can it be done with Aspose,PDF and if so, can you give us some code example on how to do this ?
Thank you.

@nick1234

Thank you for contacting support.

We would like to share with you that you may extract text along with its Position (XIndent, YIndent) and Rectangle (LLX, LLY, URX, URY), by using TextFragmentAbsorber. Please check following code snippet in your environment.

        Document document = new Document(dataDir + "Test.pdf");
        TextFragmentAbsorber tfa = new TextFragmentAbsorber("Search Term");
        document.Pages.Accept(tfa);
        foreach (TextFragment tf in tfa.TextFragments)
        {
            var position = tf.Position;
            var rectangle = tf.Rectangle;
            tf.Text = "Replaced Term";
        }
        document.Save(dataDir + "Test_18.3.pdf");

I hope this will be helpful. Please feel free to let us know if you need any further assistance.

Very helpful… Thank you.