We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Apply comments to Shape

Hi. Can you share some code example how added comments to shape from aspose. Problem that comment must be tied to the paragraph in which shapesample.zip (15.8 KB) is located.

@tvv91

Thanks for your inquiry. Please use the following code example to apply comment to Shape. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");

Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);

Comment comment = new Comment(doc, "tahir.manzoor", "TM", DateTime.Today);
shape.ParentNode.InsertAfter(comment, shape);
comment.Paragraphs.Add(new Paragraph(doc));
comment.FirstParagraph.Runs.Add(new Run(doc, "Comment text."));

doc.Save(MyDir + "18.11.docx");

Moreover, please read the following article.
How to Add a Comment

Thanks, but, it’s not what we want. Try your code on my sample with shape position some on the middle of document. Comment will be apply in top of document. On sample document green rectangle has comment on same level (same paragraph). Main task - determine paragraph, in which shape located. If using your example code, comment will be always on top of page. Result of your code: result.zip (12.9 KB)
How must be: result.zip (14.2 KB)

@tvv91

Thanks for your inquiry. We have tested the scenario using the input document (sample.docx) and have not found the shared issue while using the latest version of Aspose.Words for .NET 18.11. Please upgrade to the latest version of Aspose.Words.

If you still face problem, please ZIP and attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.

We try 18.11, but same result. I’m prepare new good demonstrative example for introduce problem.
So, we have sample file with programmaticaly created shape: result.zip (12.1 KB)
Open this file, and try add comment to shape: 1.png (43.6 KB)
Result would be like this: 2.png (35.8 KB)
Of course, this is wrong, because result must be like this: 3.png (35.9 KB)
I know root of problem - we just can’t determine paragraph, in which shape is located. But I don’t know how we can found this paragraph. Shape has Bounds property, so we know shape coordinates. But paragraph, runs hasn’t coordinates.
Otherwise, it would be a simle task. Just iterate all paragraphs on page, and comparing paragrapf coordinats with shape coordinates.

@tvv91

You can get the paragraph in which shape is located using Shape.ParentParagraph property. This property returns the immediate parent paragraph.

You want to insert the comment in the paragraph in which Shape is located. The code example shared in this thread serves this purpose.

We have checked the MS Word’s behavior. It inserts the comment in the first paragraph of document. Could you please elaborate what exact you want to achieve using Aspose.Words? We will then answer your query accordingly.