The GroupDocs.Comparison is a Java library which allows you to compare documents and see differences. Compare Microsoft Word, Excel, PowerPoint, OpenDocument, PDF, Text, HTML and many other documents, retrieve a list of changes between source and target documents, apply or reject changes and save results with GroupDocs.Comparison API. In addition to this, GroupDocs.Comparison can identify styling and formatting changes – like bold, italic, underlines, strikethroughs, font types, etc.
Changes detection algorithms used by GroupDocs.Comparison allows you to detect differences in various document parts and blocks:
Text blocks – paragraphs, words and characters
Tables
Images
Shapes etc.
Here are simple steps to compare two text files and show differences:
Initialize the Comparer object with the source document.
Add the second file using the add method of Comparer object.
Call the compare method to get the result of the comparison.
The following code snippet demonstrates the simplest case of documents comparison using a couple lines of code.
Compare documents using local files
JavaKotlin
You can also use streams to compare documents. Not only file stream, there is no problem in comparing files from internet without saving them locally, or compare files on-fly.
Compare documents using streams
JavaKotlin
Let’s say you have two contracts in DOCX format that were concluded in different years. If you use the above code to compare these contracts, you get a DOCX file where deleted elements are marked in red, added in blue, and modified in green as shown below:
Accept or Reject detected differences
GroupDocs.Comparison provides an ability to apply or discard specific changes between source and target documents and save the resultant document with (or without) selected changes.
The following are the steps to apply/reject changes to the resultant document.
Instantiate Comparer object with source document path or stream.
Call add method and specify target document’s path or stream.
The following code sample shows how to accept/reject detected differences.
JavaKotlin
Generate document pages preview
GroupDocs.Comparison allows you generate page’s previews for source, target and resultant documents using generatePreview method of a Document class.
Class PreviewOptions is used to manage preview generation process – specify page numbers, image format etc.
Please check the documentation to learn more about the library. We also offer free technical support so please feel free to contact us – we will be happy to help.