Free Support Forum - aspose.com

Comments on word... while converting HTML to Word

Hi,

I want to add comment to the doc file while converting from HTML to DOC/PDF, wanted to know how to add a comment on particluar text (from existing HTML) ......

What I did is :- Created a document object, Load html in that document

I have taken some reference from link

http://www.aspose.com/blogs/blogs/?p=2896v

Regards,

Divesh Salian

Hi Divesh,


Thanks for your inquiry. A comment in a document is imported as a Comment node in the Aspose.Words DOM. The range of a comment can span over various parts of the document text, including over many paragraphs and tables.

The CommentRangeStart and CommentRangeEnd nodes define the area of the document that the comment is applied to. The Comment node defines the actual content of the comment and provides members to access the comment properties such as Author and Time. All three comment nodes are related through the use of the ID properties on each node.

Please use the following code snippet to add comment to a paragraph in a document.

// Open an existing document to add comments to a paragraph.

Document doc = new Document(“D:\in.html”);

Node[] nodes = doc.getChildNodes(NodeType.PARAGRAPH, true).toArray();

//E.g this is the Paragraph to which comments will added

Paragraph paragraph = (Paragraph)nodes[4];

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!!!”));

comment.appendChild(commentParagraph);

//Move to paragraph where comments will be added

builder.moveTo(paragraph);

// Insert comment

builder.insertNode(comment);

// Save output document.

doc.save(“D:\AsposeOut.doc”);