Compare documents

Change detection algorithms of GroupDocs.Comparison allow 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 the source document path or stream.
  2. Call the add() method and specify the target document path or stream.
  3. Call the compare() method.

The following code snippets show how to compare two documents:

Compare local documents

import groupdocs.comparison as gc

# Initialize the comparer object with the source file path
with gc.Comparer(sourcePath) as comparer:

    # Add the target file for comparison and perform the compare operation
    comparer.add(targetPath)
    comparer.compare(output_file_name)

The output file is as follows:

Compare documents from a stream

import groupdocs.comparison as gc

def run():

    # Initialize the comparer object with the source file stream
    with open(sourcePath, 'rb') as source_stream:
        comparer = gc.Comparer(source_stream)

        # Add the target file for comparison from a stream and perform the compare operation
        with open(targetPath, 'rb') as target_stream:
            comparer.add(target_stream)
            comparer.compare(output_file_name)