Hi.
Please, could anybody tell me how is possible to find a text in a Word document (.doc) and, when the text is found, get its x,y position?
I need to know this information because once the document has been converted in PDF a digital signature process is executed with other component and it needs to print the signature in those coordinates, so I need to know them.
Regards.
Hi José,
Thanks for your inquiry. Sure you can achieve this by implementing IReplacingCallback interface. In the IReplacingCallback.Replacing event, you can get a handle to the matching nodes and obtain their positions using the classes of Aspose.Words.Layout Namespace (see LayoutEnumerator.Rectangle property). Please let me know if I can be of any further assistance.
Best regards,
Sorry, I need an example to understand how that works. I’m totally lost…
Is there any example similar to your proposed solution in the Example package?
Hi José,
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<o:p></o:p>
{
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;
}
}