Compare multiple documents protected by password

Note
This feature is available only for Word documents, PowerPoint, and Open Document presentations.

GroupDocs.Comparison allows you to compare more than two password-protected documents.

To compare several password-protected documents, follow these steps:

  1. Instantiate the LoadOptions object. Specify the password for the source document.
  2. Instantiate the Comparer object. Specify the source document path or stream and the LoadOptions object created in the previous step.
  3. Instantiate another LoadOptions object and specify the password for the target document.
  4. Call the add() method and specify the target document path or stream and the LoadOptions object created in step 3. Repeat steps 3 and 4 for every target document.
  5. Call the compare() method.

The following code snippets show how to compare several password-protected documents:

Compare several password-protected documents from a local disk

import groupdocs.comparison as gc

def compare_multiple_documents_protected_path(source_path, target_paths, source_password, target_passwords, output_file_name):
    # Initialize the comparer with the source file path and load options
    load_options_source = gc.options.LoadOptions()
    load_options_source.password = source_password
    comparer = gc.Comparer(source_path, load_options_source)

    # Add target files and load options
    for target_path, target_password in zip(target_paths, target_passwords):
        load_options_target = gc.options.LoadOptions()
        load_options_target.password = target_password
        comparer.add(target_path, load_options_target)

    # Perform the compare operation and save the result
    comparer.compare(output_file_name)

    print(f"\nDocuments compared successfully.\nCheck output in {output_file_name}.")
    

Compare several password-protected documents from a stream

import groupdocs.comparison as gc

def compare_multiple_documents_protected_path(source_path, target_paths, source_password, target_passwords, output_file_name):
    # Initialize the comparer with the source stream and load options
    with open(source_path, 'rb') as source_stream:
        load_options_source = gc.options.LoadOptions()
        load_options_source.password = source_password
        comparer = gc.Comparer(source_stream, load_options_source)

        # Add target streams and load options
        target_streams = []
        for target_path, target_password in zip(target_paths, target_passwords):
            target_stream = open(target_path, 'rb')
            target_streams.append(target_stream)
            load_options_target = gc.options.LoadOptions()
            load_options_target.password = target_password
            comparer.add(target_stream, load_options_target)

        # Perform the compare operation and save the result
        comparer.compare(output_file_name)

        # Close target streams after comparison
        for target_stream in target_streams:
            target_stream.close()

    print(f"\nDocuments compared successfully.\nCheck output in {output_file_name}.")