How to remove track changes in document?

Team,

I am using Aspose latest version for document conversion. I have attached document with this post, after conversion i am getting lot of dummy paragraph in place of track changes. It is possible to remove

Thanks,

Anbu

Hi Anbu,

Thanks for your inquiry. It would be great if you please share to which file format you are converting your input Docx. Please also share some detail about ‘dummy paragraph’. I have converted the shared Docx to Docx/Pdf/Html and have not found any issue with output files.

Anbu2Win:

How to remove track changes in document ?

Please use the RevisionCollection.rejectAll method to reject all revisions in this collection. Use the Document.acceptAllRevisions method to accept all tracked changes in the document. You can also use RevisionCollection.acceptAll method to accept all revisions in this collection. Document.getRevisions return a of revisions (tracked changes) that exist in this document.

Hope this answers your query. Please let us know if you have any more queries.

Thanks Tahir for the reply. Actually in attached document it has only one paragraph, but while iterating am getting 15 paras. How to skip that paragraph?

Document doc = new Document(".\\revision.docx");
NodeList paras = doc.selectNodes("//Paragraph");//No I18N
int paraCount = paras.getCount();
// am getting 15 paras. Where as in attached document it has only one para
for(Paragraph para : paras){
    String text = para.getText();
    // Lots of empty paragraph
    System.out.println("Content :" + text);
}

Thanks

Hi Anbu,

Thanks for sharing the detail. Please note that a valid paragraph in Microsoft Word always ends with a paragraph break character and a minimal valid paragraph consists just of a paragraph break. The Paragraph class automatically appends the appropriate paragraph break character at the end and this character is not part of the child nodes of the Paragraph, therefore a Paragraph can be empty.

I like to share with you that your input document contains the empty paragraphs. Please see the attached image for detail. Please use the following code snippet to remove empty Paragraphs from the document. Let us know if you have any more queries.

Document doc = new Document(MyDir + "revision.docx");
NodeList<Paragraph> paras = doc.selectNodes("//Paragraph");//No I18N
for(Paragraph para : paras){
    String text = para.toString(SaveFormat.TEXT).trim();
    if(text.equals(""))
        para.remove();
}
doc.save(MyDir + "Out.docx");