Get List of Changes

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Comparison MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-comparison -- dnx GroupDocs.Comparison.Mcp --yes
Folders, licensing and more →

GroupDocs.Comparison for Python via .NET populates an internal change list during the comparison. After calling compare(), retrieve the changes via get_changes().

Example 1: Get the list of changes from file paths

from groupdocs.comparison import Comparer

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

if __name__ == "__main__":
    get_list_of_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, Page: 1, Id: 0, Text: Cool
Type: 2, Page: 1, Id: 1, Text:  
Type: 3, Page: 1, Id: 2, Text: test 
Type: 2, Page: 1, Id: 3, Text:  signatures
Type: 2, Page: 1, Id: 4, Text: Our 
Type: 2, Page: 1, Id: 5, Text: char[
Type: 2, Page: 1, Id: 6, Text: 255]
Type: 2, Page: 1, Id: 7, Text:  
Type: 3, Page: 1, Id: 8, Text:

Download full output

Use case: build a custom report UI listing every difference with pagination info.

Example 2: Get the list of changes from streams

from groupdocs.comparison import Comparer

def get_list_of_changes_stream():
    with open("./source.docx", "rb") as source_stream, \
         open("./target.docx", "rb") as target_stream:
        with Comparer(source_stream) as comparer:
            comparer.add(target_stream)
            comparer.compare()
            for change in comparer.get_changes():
                print(f"Type: {change.type}, Page: {change.page_info.page_number}, Id: {change.id}, Text: {change.text}")

if __name__ == "__main__":
    get_list_of_changes_stream()

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

Type: 2, Page: 1, Id: 0, Text: Cool
Type: 2, Page: 1, Id: 1, Text:  
Type: 3, Page: 1, Id: 2, Text: test 
Type: 2, Page: 1, Id: 3, Text:  signatures
Type: 2, Page: 1, Id: 4, Text: Our 
Type: 2, Page: 1, Id: 5, Text: char[
Type: 2, Page: 1, Id: 6, Text: 255]
Type: 2, Page: 1, Id: 7, Text:  
Type: 3, Page: 1, Id: 8, Text:

Download full output

Use case: integrate diff extraction into services that operate on file streams.