Load password-protected documents

On this page

GroupDocs.Comparison allows you to compare documents that are protected with a password.

To compare password-protected documents, follow these steps:

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

The following code snippet shows how to compare password-protected documents:

def compare_multiple_documents_protected_path(output_file_name, source_path, target_paths, source_password, target_passwords, result_path):
    try:
        # 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}.")
    
    except Exception as error:
        # Handle errors
        print('An error occurred during the document comparison:', error)

On this page