Get source and target text from files

GroupDocs.Comparison for Python via .NET provides access to the source and target text for each detected change.

Get source and target text from local disk

Compare two files and print the source/target text for each change.

import groupdocs.comparison as gc

with gc.Comparer("source.docx") as comparer:
    comparer.add("target.docx")
    comparer.compare("result.docx")
    changes = comparer.get_changes()
    for change in changes:
        print()
        print("Source text:", change.source_text)
        print("Target text:", change.target_text)

🔹 Use case: Extract changed text pairs to power side-by-side diff review tools.

The result is as follows:

Get source and target text from stream

Work directly with streams and retrieve the same data programmatically.

import groupdocs.comparison as gc

with open("source.docx", "rb") as src, open("target.docx", "rb") as tgt:
    with gc.Comparer(src) as comparer:
        comparer.add(tgt)
        comparer.compare("result.docx")
        changes = comparer.get_changes()
        for change in changes:
            print()
            print("Source text:", change.source_text)
            print("Target text:", change.target_text)

🔹 Use case: Feed structured change text into analytics or translation workflows.

Close
Loading

Analyzing your prompt, please hold on...

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