Set Document Metadata on Save

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Comparison MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-comparison -- dnx GroupDocs.Comparison.Mcp --yes
Folders, licensing and more →

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