X,y coordinates of a specific text in word document

Hi

I need to get (x,y) coordinates of a particular text in word document.
Can any one help

@psaini_arc

Thanks for your inquiry. You can achieve your requirement by searching the specific text, move cursor to the matched text, insert a bookmark and get bookmark coordinates. Please check following documentation links and sample code snippet for the purpose.

Find and Replace
Aspose.Words.Layout Namespace (see LayoutEnumerator.Rectangle property)

Document doc = new Document(@"C:\Temp\input.docx");
doc.Range.Replace(new Regex("FIND MY COORDIANTES"), new MyReplaceEvaluator(), true);
doc.Save(@"C:\Temp\out.docx");
////////////////////////////////////////
private class MyReplaceEvaluator : IReplacingCallback

{

ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)

{

DocumentBuilder builder = new DocumentBuilder((Document)e.MatchNode.Document);


builder.MoveTo(e.MatchNode);

BookmarkStart start = builder.StartBookmark("temp");


builder.EndBookmark("temp");


LayoutCollector collector = new LayoutCollector((Document)e.MatchNode.Document);

LayoutEnumerator enumerator = new LayoutEnumerator((Document)e.MatchNode.Document);

enumerator.Current = collector.GetEntity(start);

Console.WriteLine("({0}, {1})", enumerator.Rectangle.Left, enumerator.Rectangle.Top);

e.MatchNode.Document.Range.Bookmarks["temp"].Remove();

return ReplaceAction.Skip;

}

}