Retrieve revisions

Dear all,

how can I retrieve all the revisions which have been made into the document in Aspose.words java?
Is it possible to distinguish between the types of the revisions(e.g. add, delete, …)?

Thanks in advance,
Marzie

Hi Marzie,

Thanks for your inquiry. Revision class represents a revision (tracked change) in a document node or style. Use RevisionType to check the type of this revision.

Please use Document.Revisions property to get revisions (tracked changes) that exist in this document. The returned collection is a “live” collection, which means if you remove parts of a document that contain revisions, the deleted revisions will automatically disappear from this collection.

Moreover, Inline.IsDeleteRevision property returns true if this object was deleted in Microsoft Word while change tracking was enabled.

Inline.IsInsertRevision property returns true if this object was inserted in Microsoft Word while change tracking was enabled.

Please check the following code example. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");
for (Revision revision : doc.getRevisions())
{
    if (revision.getRevisionType() == RevisionType.INSERTION)
    {
        System.out.println("Insert Revision");
    }
    else if (revision.getRevisionType() == RevisionType.DELETION)
    {
        System.out.println("Delete Revision");
    }
}

Dear Tahir,

Thanks a lot for your response. It really helped.

Best,
Marzie

Dear Tahir,

besides the revision types, can we also get the text which are added or deleted from the document?

Thanks in advance,
Marzie

Hi Marzie,

Thanks for your inquiry. Run.IsDeleteRevision property returns true if this object was deleted in Microsoft Word while change tracking was enabled.

Run.IsInsertRevision property returns true if this object was inserted in Microsoft Word while change tracking was enabled.

Please use following code example to achieve your requirements. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");
NodeCollection nodes = doc.getChildNodes(NodeType.RUN, true);
for (Run run : (Iterable)nodes)
{
    if (run.isDeleteRevision())
    {
        System.out.println("Deleted text : " + run.getText());
    }
    if (run.isInsertRevision())
    {
        System.out.println("Inserted text: " + run.getText());
    }
}

Dear Tahir,

Thanks a lot, it really helped.

Best,
Marzie

Hi Marzie,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

A post was merged into an existing topic: Extract all formatted content from a word document which has track changes