Accept or Reject revisions
Leave feedback
On this page
GroupDocs.Comparison allows you to get revisions from a Docx file format, process, and save the processing result. To take revisions from a document, accept / reject revisions, and write the processing result to the output file, follow these steps:
- Instantiate the RevisionHandler object. Specify the source document path or stream.
- Call the getRevisions method to get the revision list.
- Call the setAction property of the object to be changed. Specify the RevisionAction.ACCEPT or RevisionAction.REJECT value.
- Call the applyRevisionChanges method. Specify the created instance of the ApplyRevisionOptions class and path or stream of the output document, collecting changes in the revisions.
You can process all changes together within one action.To handle all changes at once, follow these steps:
- Instantiate the RevisionHandler object. Specify the source document path or stream.
- Call the applyRevisionChanges method. Specify the ApplyRevisionOptions object and one of the (RevisionAction.Accept, RevisionAction.Reject or RevisionAction.NONE) values.
The main properties of the ApplyRevisionOptions class are as follows:
- Changes is a list of revision changes that need to be applied to the final document
- CommonHandler allows you to define one action to handle all revision
If you do not specify the path or file to the output document for the applyRevisionChanges method, the source file is rewritten.
The following code snippets show how to get revisions from a document, accept / reject detected revisions and save changes to the output document:
try (RevisionHandler revisionHandler = new RevisionHandler(withRevisionFile)) {
List<RevisionInfo> revisionList = revisionHandler.getRevisions();
for (RevisionInfo revision : revisionList) {
if (revision.getType() == RevisionType.INSERTION) {
revision.setAction(RevisionAction.Accept);
}
}
ApplyRevisionOptions revisionOptions = new ApplyRevisionOptions();
revisionOptions.setChanges(revisionList);
revisionHandler.applyRevisionChanges(resultFile, revisionOptions);
}
try (RevisionHandler revisionHandler = new RevisionHandler(withRevisionInputStream)) {
List<RevisionInfo> revisionList = revisionHandler.getRevisions();
for (RevisionInfo revision : revisionList) {
if (revision.getType() == RevisionType.Insertion) {
revision.setAction(RevisionAction.Accept);
}
}
ApplyRevisionOptions revisionOptions = new ApplyRevisionOptions(revisionList);
revisionHandler.applyRevisionChanges(resultOutputStream, revisionOptions);
}
try (RevisionHandler revisionHandler = new RevisionHandler(withRevisionFile)) {
ApplyRevisionOptions revisionOptions = new ApplyRevisionOptions();
revisionOptions.setCommonHandler(RevisionAction.Accept);
revisionHandler.applyRevisionChanges(resultFile, revisionOptions);
}
Below are the source and output files based on the code presented earlier.
Source file | Result file |
---|---|
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.