Accept or Reject document changes
GroupDocs.Comparison provides an ability to apply or discard specific changes between source and target files and save result with (or without) selected changes.
The following are the steps to apply/reject changes to resultant file.
- Instantiate Comparer objectwith source document path or stream;
- Call add method and specify path target document path or stream;
- Call compare method;
- Call getChanges method and obtain detected changes list;
- Set ComparisonAction of needed change object to ComparisonAction.ACCEPT or ComparisonAction.REJECT value;
- Call applyChanges method and pass collection of changes to it;
ApplyChangeOptions class:
- getChanges - List of changes that must be applied (or not) to the resulting document;
The following code sample shows how to accept/reject detected changes.
Accept or Reject changes from local disk
try (Comparer comparer = new Comparer("C:\\source.pdf")) {
comparer.add("C:\\target.pdf");
comparer.compare("C:\\result.pdf");
}
Accept or Reject changes from stream
try (Comparer comparer = new Comparer("C:\\source.pdf")) {
comparer.add("C:\\target.pdf");
comparer.compare();
ChangeInfo[] changes = comparer.getChanges();
changes[0].setComparisonAction(ComparisonAction.REJECT);
comparer.applyChanges(new FileOutputStream("C:\\result.pdf"), new ApplyChangeOptions(changes));
}
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples:
- GroupDocs.Comparison for Java examples, plugins, and showcase
- GroupDocs.Comparison for .NET examples, plugins, and showcase
- Document Comparison for Java App Dropwizard UI Modern Example
- Document Comparison for Java Spring UI Example
- Document Comparison for .NET MVC UI Example
- Document Comparison for .NET App WebForms UI Modern Example
Free Online App
Along with full-featured Java library we provide simple, but powerful free Apps. You are welcome to compare your DOC or DOCX, XLS or XLSX, PPT or PPTX, PDF, EML, EMLX, MSGand other documents with free to use online GroupDocs Comparison App.