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

Free Support Forum - aspose.com

Insert Comment for a selection

How to insert a comment for a selected range in the document.

I’m using Aspose.words JAVA API


Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for your inquiry. You can use the following code for inserting comments into the document.

// Create new document

Document doc = new Document();

// Create DocumentBuilder

DocumentBuilder builder = new DocumentBuilder(doc);

// Insert some text into the document

builder.write("Some text is added.");

// Create comment

Comment comment = new Comment(doc);

// Add comment to the current paragraph


// Add text into the comment

comment.getParagraphs().add(new Paragraph(doc));

comment.getFirstParagraph().getRuns().add(new Run(doc, "Comment text."));

// Save document


Please see the following link for more information.


I hope this could help you.

Best regards.

Thanks for your prompt reply

I have no problems in inserting a comment into document but I need to set the selection-text for the comment.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Unfortunately this feature is not available in Aspose.Words. This is known issue # 1012 in our defect database. I will notify you as soon as this feature will be available.

Best regards.

We are happy to notify you that the latest version of Aspose.Words supports commented ranges. You can download the latest version fo Aspose.Words from here..

Here is a simple code example, which allows insertion commented range into the document:

// Create an empty document and DocumentBuilder object.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

// Create a Comment.

Comment comment = new Comment(doc);

// Insert some text into the comment.

Paragraph commentParagraph = new Paragraph(doc);

commentParagraph.AppendChild(new Run(doc, "This is comment!!!"));


// Create CommentRangeStart and CommentRangeEnd.

int commentId = 0;

CommentRangeStart start = new CommentRangeStart(doc, commentId);

CommentRangeEnd end = new CommentRangeEnd(doc, commentId);

// Insert some text into the document.

builder.Write("This is text before comment ");

// Insert comment and comment range start.



// Insert some more text.

builder.Write("This is commented text ");

// Insert end of comment range.


// And finaly insert some more text.

builder.Write("This is text aftr comment");

// Save output document.


Best regards,