Set Document Metadata on Save

The comparison result document can carry metadata (author, organization, creation date, etc.). Use SaveOptions.clone_metadata_type to choose where it comes from:

  • MetadataType.SOURCE — clone metadata from the source document.
  • MetadataType.TARGET — clone metadata from the target document.
  • MetadataType.FILE_AUTHOR — set user-defined metadata via SaveOptions.file_author_metadata.

Example 1: Use metadata from the source file

from groupdocs.comparison import Comparer
from groupdocs.comparison.options import SaveOptions, MetadataType

def set_metadata_from_source():
    with Comparer("./source.docx") as comparer:
        comparer.add("./target.docx")
        save_options = SaveOptions()
        save_options.clone_metadata_type = MetadataType.SOURCE
        comparer.compare("./result.docx", save_options)

if __name__ == "__main__":
    set_metadata_from_source()

source.docx is the source file used in this example. Click here to download it.

target.docx is the target file used in this example. Click here to download it.

Binary file (DOCX, 25 KB)

Download full output

Example 2: Use metadata from the target file

from groupdocs.comparison import Comparer
from groupdocs.comparison.options import SaveOptions, MetadataType

def set_metadata_from_target():
    with Comparer("./source.docx") as comparer:
        comparer.add("./target.docx")
        save_options = SaveOptions()
        save_options.clone_metadata_type = MetadataType.TARGET
        comparer.compare("./result.docx", save_options)

if __name__ == "__main__":
    set_metadata_from_target()

source.docx is the source file used in this example. Click here to download it.

Binary file (DOCX, 25 KB)

Download full output

Example 3: Set user-defined metadata

from groupdocs.comparison import Comparer
from groupdocs.comparison.options import SaveOptions, MetadataType, FileAuthorMetadata

def set_user_defined_metadata():
    with Comparer("./source.docx") as comparer:
        comparer.add("./target.docx")

        author_metadata = FileAuthorMetadata()
        author_metadata.author = "Tom"
        author_metadata.company = "GroupDocs"
        author_metadata.last_save_by = "Jack"

        save_options = SaveOptions()
        save_options.clone_metadata_type = MetadataType.FILE_AUTHOR
        save_options.file_author_metadata = author_metadata

        comparer.compare("./result.docx", save_options)

if __name__ == "__main__":
    set_user_defined_metadata()

source.docx is the source file used in this example. Click here to download it.

Binary file (DOCX, 25 KB)

Download full output

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.