To protect the output document, follow these steps:
Instantiate the Comparer object. Specify the source document path or stream.
Call the add() method. Specify the target document path or stream.
Instantiate the CompareOptions object. Call the password_save_option method and specify the PasswordSaveOption.USER value.
Instantiate the SaveOptions object. Call the password property to specify a password string.
Call the compare() method. Specify the SaveOptions and CompareOptions objects as parameters.
The following code snippet shows how to compare documents and protect the output document with a password:
importgroupdocs.comparisonasgcdefset_password_for_resultant_document(output_file_path,source_file_path,target_file_path):try:# Initialize comparer with the source documentwithgc.Comparer(source_file_path)ascomparer:# Add the target document for comparisoncomparer.add(target_file_path)# Set comparison optionscompare_options=gc.options.CompareOptions()compare_options.password_save_option=gc.options.PasswordSaveOption.USER# Set save optionssave_options=gc.options.SaveOptions()save_options.password="3333"# Compare the documents and save the resultcomparer.compare(output_file_path,save_options,compare_options)# Log the success message with the output file pathprint(f"\nDocuments compared successfully.\nCheck output in {output_file_path}.")exceptExceptionaserror:# Error handlingprint(f'An error occurred during the document comparison: {error}')
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.