Hi,
Is it possible to do comparisons to multiple versions of document and then apply the revisions from each compare to the original document to create a final document with all the revisions?
example:
I have v1.docx with simple content = “This is a test document”.
In v2.docx, content = “This is a test document updated”. Author = “User A”
In v3.docx, content = “This is a test document updated final”. Author = “User B”
I can compare v1 with v2 and get the revision, and also v2 with v3 and get its revision. But I would like to get a final document with combined revisions from first and second comparison: insertion of “updated” by User A and insertion of “final” by User B
@ryanwidjaya
Combining Multiple Revisions into a Final Document Using Aspose.Words
Yes, it’s possible to compare multiple versions of a document and then apply the revisions from each comparison to the original document to create a final document with all the revisions using Aspose.Words.
Here’s a step-by-step guide on how to accomplish this:
-
Compare v1.docx with v2.docx:
- This comparison will produce a document with changes marked by “User A”.
-
Compare v2.docx with v3.docx:
- This comparison will produce a document with changes marked by “User B”.
-
Combine the revisions:
- Apply the changes from both comparison results to the original document in sequence.
Here is a code sample demonstrating this process:
// Load the original and revised documents
Document docOriginal = new Document("v1.docx");
Document docFirstRevision = new Document("v2.docx");
Document docSecondRevision = new Document("v3.docx");
// Compare the original document with the first revision and accept changes
docOriginal.Compare(docFirstRevision, "User A", DateTime.Now);
docOriginal.AcceptAllRevisions();
// Compare the current document with the second revision and accept changes
docOriginal.Compare(docSecondRevision, "User B", DateTime.Now);
docOriginal.AcceptAllRevisions();
// Save the final document with all revisions combined
docOriginal.Save("FinalDocument.docx");
Detailed Steps:
-
Load the Original Document:
- Create instances of the
Document
class for the original and revised documents using file paths.
-
Compare Documents:
- Use the
Compare
method of the Document
class to compare the original document with the first revision. This will mark changes authored by “User A”.
- Use the
AcceptAllRevisions
method to apply these changes to the original document.
-
Compare Again:
- Repeat the
Compare
method for the document resulting from the first comparison and the second revision. This will mark changes authored by “User B”.
-
Accept Revisions:
- Apply the changes from the second comparison using the
AcceptAllRevisions
method.
-
Save the Final Document:
- Save the updated document as a new file which will contain all the applied revisions.
Additional Information and Documentation:
By following this approach, you will have a final document that merges all revisions from each comparison, maintaining the changes made by each author in sequence.
If you need further assistance or encounter any issues, feel free to ask!
using AcceptAllRevisions will remove the tracked change. I want to keep the tracked changes.
@ryanwidjaya Looks like you need Combine feature (Review Tab > Compare > Combine) of Word. Unfortunately, Aspose.Words does not support this feature yet.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSNET-13484
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Is there a way to loop through the RevisionsCollection from the 2 comparison and build it from scratch from v1?
@ryanwidjaya Unfortunately, there is no way to achieve this using existing API.