Get List of Changes

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.

Close
Loading

Analyzing your prompt, please hold on...

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