Compare documents

Changes detection algorithms used by GroupDocs.Comparison allows you to detect changes in different document parts and blocks:

  • Text blocks - paragraphs, words and characters
  • Tables
  • Images
  • Shapes etc.

GroupDocs.Comparison highlights detected changes with different colors:

  • Added – blue 
  • Modified – green
  • Style – green
  • Deleted – red

You can customize the changes styling scheme using different formatting - italic, bold, underlined, strike through, etc.

To compare two documents, follow these steps:

  1. Instantiate the Comparer object with source document path or stream.
  2. Call the add() method and specify target document path or stream.
  3. Call the compare() method.

The following code snippets show how to compare two documents:

Compare local documents

import com.groupdocs.comparison.Comparer;
import java.nio.file.Path;
// ...

try (Comparer comparer = new Comparer("source.pdf")) {
    comparer.add("target.pdf");
    final Path resultPath = comparer.compare("result.pdf");
}

The output file is as follows:

Compare documents from stream

import com.groupdocs.comparison.Comparer;
import java.nio.file.Path;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
// ...

try (Comparer comparer = new Comparer(sourceInputStream)) {
    comparer.add(targetInputStream);
    final Path resultPath = comparer.compare(resultOutputStream);
}