A document can contain some metadata information, such as author, organization, etc. GroupDocs.Comparison allows you to select metadata sources when saving the output document.
Possible metadata sources are as follows:
Source document metadata
Target document metadata
User-defined metadata
To set output document metadata, 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 SaveOptions object. Set the appropriate MetadataType via clone_metadata_type property.
Call the compare() method. Specify the SaveOptions object as a parameter.
The following code snippets show how to set output document metadata:
Set metadata from the source file
importgroupdocs.comparisonasgcdefset_document_metadata_on_save(output_file_path,source_file_path,target_file_path):# Initialize comparer with the source documentwithgc.Comparer(source_file_path)ascomparer:# Add the target document for comparisoncomparer.add(target_file_path)# Set comparison optionssave_options=gc.options.SaveOptions()save_options.clone_metadata_type=gc.options.MetadataType.SOURCE# Compare the documents and save the resultcomparer.compare(output_file_path,save_options)# Log the success message with the output file pathprint(f"\nDocuments compared successfully.\nCheck output in {output_file_path}.")
Set metadata from the target file
importgroupdocs.comparisonasgcdefset_document_metadata_on_save(output_file_path,source_file_path,target_file_path):# Initialize comparer with the source documentwithgc.Comparer(source_file_path)ascomparer:# Add the target document for comparisoncomparer.add(target_file_path)# Set comparison optionssave_options=gc.options.SaveOptions()save_options.clone_metadata_type=gc.options.MetadataType.TARGET# Compare the documents and save the resultcomparer.compare(output_file_path,save_options)# Log the success message with the output file pathprint(f"\nDocuments compared successfully.\nCheck output in {output_file_path}.")
Set user-defined metadata
importgroupdocs.comparisonasgcdefset_document_metadata_on_save(output_file_path,source_file_path,target_file_path):# Initialize comparer with the source documentwithgc.Comparer(source_file_path)ascomparer:# Add the target document for comparisoncomparer.add(target_file_path)# Set file author metadatafile_author_metadata=gc.options.FileAuthorMetadata()file_author_metadata.author="Tom"file_author_metadata.company="GroupDocs"file_author_metadata.last_save_by="Jack"# Set comparison optionssave_options=gc.options.SaveOptions()save_options.clone_metadata_type=gc.options.MetadataType.FILE_AUTHORsave_options.file_author_metadata=file_author_metadata# Compare the documents and save the resultcomparer.compare(output_file_path,save_options)# Log the success message with the output file pathprint(f"\nDocuments compared successfully.\nCheck output in {output_file_path}.")
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.