Accept or Reject revisions

GroupDocs.Comparison allows you to get revisions from a DOCX file format, process, and save the processing result. To obtain revisions from a document, accept or reject revisions, and write the processing result to the output file, follow these steps:

  1. Instantiate the RevisionHandler object. Specify the source document path or stream.
  2. Call the getRevisions method to get the revision list.
  3. Call the setAction property of the object to be changed. Specify the RevisionAction.ACCEPT or RevisionAction.REJECT value.
  4. 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:

  1. Instantiate the RevisionHandler object. Specify the source document path or stream.
  2. 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 or reject the detected revisions and save changes to the output document:

Accept or Reject revisions from a local disk

try {
  const revisionHandler = new groupdocs.comparison.RevisionHandler(withRevisionFile)
  List<RevisionInfo> revisionList = revisionHandler.getRevisions();
  for (RevisionInfo revision : revisionList) {
      if (revision.getType() == groupdocs.comparison.RevisionType.INSERTION) {
          revision.setAction(groupdocs.comparison.RevisionAction.Accept);
      }
  }
  const revisionOptions = new groupdocs.comparison.ApplyRevisionOptions();
  revisionOptions.setChanges(revisionList);
  revisionHandler.applyRevisionChanges(resultFile, revisionOptions);
}

Accept or Reject revisions from a stream

try {
  const revisionHandler = new groupdocs.comparison.RevisionHandler(withRevisionInputStream)
  List<RevisionInfo> revisionList = revisionHandler.getRevisions();
  for (RevisionInfo revision : revisionList) {
      if (revision.getType() == groupdocs.comparison.RevisionType.Insertion) {
          revision.setAction(groupdocs.comparison.RevisionAction.Accept);
      }
  }
  const revisionOptions = new groupdocs.comparison.ApplyRevisionOptions(revisionList);
  revisionHandler.applyRevisionChanges(resultOutputStream, revisionOptions);
}

Accept or Reject all revisions

try {
  const revisionHandler = new groupdocs.comparison.RevisionHandler(withRevisionFile)
  const revisionOptions = new groupdocs.comparison.ApplyRevisionOptions();
  revisionOptions.setCommonHandler(groupdocs.comparison.RevisionAction.Accept);
  revisionHandler.applyRevisionChanges(resultFile, revisionOptions);
}

Result of revision processing

Below are the source and output files based on the code presented earlier.

Source fileResult file