[Aspose.Word] Get Comment Text Node Position

Hi Guys,

I am in the middle of confusion for using the tools for Aspose.Word. The scope is about extracting position node of text that is commented. Here is the screenshot for the clarification.

http://i60.tinypic.com/4s1ou8.jpg

So from the pict, is there any way from the tools I could get the:
- Node Position of the pointed arrow?
- The value of “this text selected”
- And I able to create image on top of “this text selected”

Any relevant information would be really appreciated.

Thanks guys.

Hi Robertus,

Thanks for your inquiry. First of all, please note that Aspose.Words is quite
different from the Microsoft Word’s Object Model in that it represents
the document as a tree of objects more like an XML DOM tree. If
you worked with any XML DOM library you will find it is easy to
understand and work with Aspose.Words. When you load a Word document
into Aspose.Words, it builds its DOM and all document elements and
formatting are simply loaded into memory. Please read the following
articles for more information on DOM:
https://docs.aspose.com/words/net/aspose-words-document-object-model/
https://docs.aspose.com/words/net/logical-levels-of-nodes-in-a-document/

*robertus:

  • Node Position of the pointed arrow?*

Please note that MS Word document is flow document and does not contain any information about its layout into lines and pages. Therefore, technically there is no “Page” concept in Word document. Pages are created by Microsoft Word on the fly.

Aspose.Words uses our own Rendering Engine to layout documents into pages. The Aspose.Words.Layout namespace provides classes that allow to access information such as on what page and where on a page particular document elements are positioned, when the document is formatted into pages. Please read about LayoutCollector and LayoutEnumerator from here:
https://reference.aspose.com/words/net/aspose.words.layout/layoutcollector/
https://reference.aspose.com/words/net/aspose.words.layout/layoutenumerator/

Please use the following code example to get the position of CommentRangeStart node.

Document doc = new Document(MyDir + "in.docx");
LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
var collection = doc.GetChildNodes(NodeType.CommentRangeStart, true);
foreach (CommentRangeStart cStart in collection)
{
    var renderObject = layoutCollector.GetEntity(cStart);
    layoutEnumerator.Current = renderObject;
    RectangleF location = layoutEnumerator.Rectangle;
}

*robertus:

  • The value of “this text selected”*

The Comment class represents a container for text of a comment. A comment is an annotation which is anchored to a region of text or to a position in text. A comment can contain an arbitrary amount of block-level content.

If a Comment object occurs on its own, the comment is anchored to the position of the Comment object.

To anchor a comment to a region of text three objects are required: Comment, CommentRangeStart and CommentRangeEnd. All three objects need to share the same Id value.

Please read the Run nodes between CommentRangeStart and CommentRangeEnd and get the text using Run.Text property.

*robertus:

  • And I able to create image on top of “this text selected”*

Please get the position of CommentRangeStart node using the code above and insert the image using DocumentBuilder.InsertImage Method (String).