Wiki
Clone wikiAspose Java for Docx4j / Working-with-Comments
Aspose.Words
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.write("Some text is added."); Comment comment = new Comment(doc, "Aspose", "As", new Date()); builder.getCurrentParagraph().appendChild(comment); comment.getParagraphs().add(new Paragraph(doc)); comment.getFirstParagraph().getRuns().add(new Run(doc, "Comment text.")); doc.save("data/Aspose_Comments.docx");
Docx4j
outputfilepath = "data/Docx4j_CommentsSample.docx"; boolean save = (outputfilepath == null ? false : true); WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage .createPackage(); // Create and add a Comments Part CommentsPart cp = new CommentsPart(); wordMLPackage.getMainDocumentPart().addTargetPart(cp); // Part must have minimal contents Comments comments = factory.createComments(); cp.setJaxbElement(comments); // Add a comment to the comments part java.math.BigInteger commentId = BigInteger.valueOf(0); Comment theComment = createComment(commentId, "fred", null, "my first comment"); comments.getComment().add(theComment); // Add comment reference to document P paraToCommentOn = wordMLPackage.getMainDocumentPart() .addParagraphOfText("here is some content"); paraToCommentOn.getContent().add(createRunCommentReference(commentId)); // ++, for next comment ... commentId = commentId.add(java.math.BigInteger.ONE); wordMLPackage.save(new java.io.File(outputfilepath));
Download Source Code
Updated