Currently I am working on the project Document management sys using Aspose.word which includes saving, editing, locking etc. Now my requirement is to lock the document once it is finalized and then add comments at the end. User can add comments / text at the end and don’t able to edit the main doc.
Sure, you can add a comment at the end of document by using the following code snippet:
Calendar cal = Calendar.getInstance();
cal.set(2009, 11, 9); //year is as expected, month is zero based, date is as expected
Date dt = cal.getTime();
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentEnd();
builder.write("Some text is added.");
Comment comment = new Comment(doc, "Amy Lee", "AL", dt);
builder.getCurrentParagraph().appendChild(comment);
comment.getParagraphs().add(new Paragraph(doc));
comment.getFirstParagraph().getRuns().add(new Run(doc, "Comment text."));
doc.save("C:\Temp\out.docx");
Hope such approach will satisfy your needs. Please let me know if you need more information, I will be glad to help you.
Currently I am using the below code to iterate through each section and its sub node.
Document oldDoc = new Document("D:\test.docm");
Iterator sectionIterator = oldDoc.getSections().iterator();
while (sectionIterator.hasNext())
{
Section section = (Section)sectionIterator.next();
Body bdy = section.getBody();
System.out.println("Body text : " + bdy.getText());
Iterator headerItr = section.getHeadersFooters().iterator();
while (headerItr.hasNext())
{
HeaderFooter headerFooter = (HeaderFooter)headerItr.next();
System.out.println("Node Name : " + headerFooter.getHeaderFooterType() + " text : " + headerFooter.getText());
}
Iterator childNodesIterator = section.getBody().getChildNodes().iterator();
while (childNodesIterator.hasNext())
{
Node insertedNode = (Node)childNodesIterator.next();
System.out.println("Node Name : " + insertedNode.getNodeType() + " text : " + insertedNode.getText());
}
}
Using above i can see the header,footer and body …
Now i want to convert the complete document into 3 x StructuredDocumentTags (SdtType.RICH_TEXT)
for header,footer and body…
Thanks for your inquiry. Could you please attach your input Word document (test.docm) and your expected document (you can create your expected document manually by using Microsoft Word). I will investigate your scenario and provide you more information.