Quick Start Guide

This guide walks you through installing GroupDocs.Comparison for Python via .NET and comparing two documents end to end. By the end you will have a working environment, an output file showing the differences between two sample documents, and the code skeleton to extend for your own use cases.

Prerequisites

  • Python 3.5 or newer — verify with python --version.
  • A package manager — pip is bundled with Python.
  • Two sample documents to compare. You can download source.docx and target.docx used in this guide, or use your own.

On Linux and macOS, GroupDocs.Comparison also requires libgdiplus and font support — see the installation guide for the exact commands.

Step 1 — Install the package

Install GroupDocs.Comparison from PyPI:

pip install groupdocs-comparison-net

The wheel is roughly 150 MB and bundles the .NET runtime; no further setup is required on Windows.

Step 2 — Compare two documents

Save the following snippet as quick_start.py in the same folder as source.docx and target.docx, then run it with python quick_start.py.

from groupdocs.comparison import Comparer

def quick_start():
    # Initialize Comparer with the source document and add the target.
    with Comparer("./source.docx") as comparer:
        comparer.add("./target.docx")
        # The result file contains the merged comparison highlighting added,
        # deleted, modified, and style changes.
        comparer.compare("./result.docx")

if __name__ == "__main__":
    quick_start()

source.docx is the source file used in this example. Click here to download it.

target.docx is the target file used in this example. Click here to download it.

Binary file (DOCX, 25 KB)

Download full output

Open result.docx to see the differences highlighted in colour: insertions in blue, deletions in red, style changes in green.

Step 3 — Inspect detected changes programmatically

Beyond writing a merged result file, you can iterate over the individual changes:

from groupdocs.comparison import Comparer

def list_changes():
    with Comparer("./source.docx") as comparer:
        comparer.add("./target.docx")
        comparer.compare()
        for change in comparer.get_changes():
            print(f"Type: {change.type}, Text: {change.text}")

if __name__ == "__main__":
    list_changes()

source.docx is the source file used in this example. Click here to download it.

target.docx is the target file used in this example. Click here to download it.

Type: 2, Text: Cool
Type: 2, Text:  
Type: 3, Text: test 
Type: 2, Text:  signatures
Type: 2, Text: Our 
Type: 2, Text: char[
Type: 2, Text: 255]
Type: 2, Text:  
Type: 3, Text:

Download full output

Evaluation vs licensed mode

Without a license, GroupDocs.Comparison processes only the first two pages of any document and stamps trial badges on the output. To unlock the full feature set, apply a license — either via the GROUPDOCS_LIC_PATH environment variable (zero-code) or by calling License().set_license(path). Request a free 30-day temporary license at purchase.groupdocs.com/temporary-license.

See Licensing and subscription for the full set of options, including metered licensing and stream-based license loading.

Next steps

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.