And you can build logic on the following C# code of Aspose.Words for .NET API to extract coordinates of content control in Word document:
Document doc = new Document("C:\\Temp\\21.6.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
// Get the Content Control you want to pbtain posiiotn of
StructuredDocumentTag sdtSdtCheckBox =
(StructuredDocumentTag)doc.GetChildNodes(NodeType.StructuredDocumentTag, true)[0];
// insert a temporary bookmark around the content control
BookmarkStart start = builder.StartBookmark("bm_1");
BookmarkEnd end = builder.EndBookmark("bm_1");
sdtSdtCheckBox.ParentNode.InsertBefore(start, sdtSdtCheckBox);
sdtSdtCheckBox.ParentNode.InsertAfter(end, sdtSdtCheckBox);
// Following code will return the (x, y) coordinates of Content Control in Inches
LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
layoutEnumerator.Current = layoutCollector.GetEntity(start);
layoutEnumerator.MoveNext();
Console.WriteLine("({0}, {1})", layoutEnumerator.Rectangle.Left / 72, layoutEnumerator.Rectangle.Top / 72);
The textbox containing the content control will be placed at an absolute position and it will not move with the addition/removal of content. Please also share your expected Word DOCX file showing the desired output here for our reference. You can create this file manually by using MS Word. It would be great if you please also list the complete steps that you performed in MS Word to create the expected file. We will then provide you code to achieve the same output by using Aspose.Words.
I will describe my use case. Requirement is that I will be given a set of coordinates with page number and i need to insert some place holder in the document at the given coordinates. Then document will go in multiple approval iteration where it will get updated.
Then once the document is approved , i will need to return coordinates for those placeholders and they may be different from initial coordinates as document might have changed.
Please suggest how to achieve this use case using aspose.
How can you meet this requirement by using MS Word? Can you please compress the following resources into ZIP format and attach the .zip file here for testing?
Your source Word document that you want to insert placeholder in
The intermediate DOCX file containing the placeholder at specific coordinates in some page
The final DOCX file (after making some changes). You can create these documents manually by using MS Word.
Please also list the complete steps you performed in MS Word to produce intermediate and final DOCX files on your end.
We will then investigate the scenario further on our end and provide you code to achieve the same outputs by using Aspose.Words.
Thanks for the reply. I do not have an example document ready.
Just wanted to get some idea on how can we achieve this use case. We need to keep some identifier in the document at a given coordinate (This will be provided by the UI which will be used for signing purpose). Then once the document is approved , we need to return updated coordinates of that identifier , which the client will send to docu sign.
You can move cursor to any inline node in Word document and then insert bookmark there. If you remove or add new content in MS Word, then this bookmark will move accordingly and later on you can get the bookmark and bookmarkâs position easily.