Instantiate the Comparer object. Specify the source document path or stream.
Call the add() method and specify the target document path or stream. Repeat this step for every target document.
Call the compare() method.
The following code snippets show how to several documents:
Compare several documents from a local disk
importgroupdocs.comparisonasgcdefcompare_multiple_documents(source_path,target_paths,result_path,output_directory,output_file_name):# Initialize the comparer with the source filecomparer=gc.Comparer(source_path)# Add target filesfortarget_pathintarget_paths:comparer.add(target_path)# Set comparison options and save optionssave_options=gc.options.SaveOptions()compare_options=gc.options.CompareOptions()# Perform the compare operation and save the resultcomparer.compare(output_file_name,save_options,compare_options)print(f"\nDocuments compared successfully.\nCheck output in {output_file_name}.")
The result is as follows:
Compare several documents from a stream
importgroupdocs.comparisonasgcdefcompare_multiple_documents(output_directory,output_file_name,sourcePath,targetPath1,targetPath2,targetPath3):# Initialize the comparer with the source file streamwithopen(sourcePath,'rb')assource_stream:comparer=gc.Comparer(source_stream)# Add the target file streamswithopen(targetPath1,'rb')astarget_stream1, \
open(targetPath2,'rb')astarget_stream2, \
open(targetPath3,'rb')astarget_stream3:comparer.add(target_stream1)comparer.add(target_stream2)comparer.add(target_stream3)# Perform the compare operation and save the resultcomparer.compare(output_file_name)print(f"\nDocuments compared successfully.\nCheck output in {output_file_name}.")
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.