eSign PDF with Metadata signature

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.Signature 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-signature -- dnx GroupDocs.Signature.Mcp --yes
Folders, licensing and more →

Overview

GroupDocs.Signature provides PdfMetadataSignature class to specify different Metadata signature objects for MetadataSignOptions instance. PDF document metadata is hidden attributes, some of them are visible only over viewing standard document properties like Author, Creation Date, Producer, Entry, Keywords etc.
PDF document metadata contains 3 fields: Name, Value and TagPrefix, combination of Name and Tag prefix should be unique.

PDF document metadata could keep big amount of data that provides ability to keep serialized custom objects with additional encryption in there.

Here are the steps to add metadata signatures into PDF document with GroupDocs.Signature:

How to eSign PDF with Metadata signature

This example shows how to sign PDF document with several e-signatures as metadata.

from datetime import datetime

from groupdocs.signature import Signature
from groupdocs.signature.options import MetadataSignOptions
from groupdocs.signature.domain import PdfMetadataSignature


def sign_pdf():
    with Signature("sample.pdf") as signature:
        options = MetadataSignOptions()

        # Add metadata signatures with values of different types
        options.add(PdfMetadataSignature("Author", "Mr.Scherlock Holmes"))  # text
        options.add(PdfMetadataSignature("CreatedOn", datetime.now()))      # date and time
        options.add(PdfMetadataSignature("DocumentId", 123456))             # whole number
        options.add(PdfMetadataSignature("SignatureId", 123.456))           # floating-point number

        # Sign the document and save the result
        result = signature.sign("signed.pdf", options)
        print(f"Signed with {len(result.succeeded)} metadata signature(s):")
        for item in result.succeeded:
            print(f"  {item.name}")


if __name__ == "__main__":
    sign_pdf()

sample.pdf is the sample file used in this example. Click here to download it.

Binary file (PDF, 36 KB)

Download full output

How to eSign PDF with standard metadata signatures

This example shows how to sign PDF document with standard embedded PDF document metadata signatures. If PDF metadata signature already exists with same name its value will be overwritten.

from datetime import datetime, timedelta

from groupdocs.signature import Signature
from groupdocs.signature.options import MetadataSignOptions
from groupdocs.signature.domain import PdfMetadataSignatures


def sign_pdf_standard():
    with Signature("sample.pdf") as signature:
        options = MetadataSignOptions()

        # Copy the standard PDF metadata signatures with new values
        now = datetime.now()
        signatures = [
            PdfMetadataSignatures.AUTHOR.clone("Mr.Scherlock Holmes"),
            PdfMetadataSignatures.CREATE_DATE.clone(now - timedelta(days=1)),
            PdfMetadataSignatures.METADATA_DATE.clone(now - timedelta(days=2)),
            PdfMetadataSignatures.CREATOR_TOOL.clone("GD.Signature-Test"),
            PdfMetadataSignatures.MODIFY_DATE.clone(now - timedelta(days=13)),
            PdfMetadataSignatures.PRODUCER.clone("GroupDocs-Producer"),
            PdfMetadataSignatures.ENTRY.clone("Signature"),
            PdfMetadataSignatures.KEYWORDS.clone("GroupDocs, Signature, Metadata, Creation Tool"),
            PdfMetadataSignatures.TITLE.clone("Metadata Example"),
            PdfMetadataSignatures.SUBJECT.clone("Metadata Test Example"),
            PdfMetadataSignatures.DESCRIPTION.clone("Metadata Test example description"),
            PdfMetadataSignatures.CREATOR.clone("GroupDocs.Signature"),
        ]

        # Add all of them to the options at once
        options.signatures.add_range(signatures)

        # Sign the document and save the result
        result = signature.sign("signed_standard.pdf", options)
        print(f"Signed with {len(result.succeeded)} metadata signature(s)")


if __name__ == "__main__":
    sign_pdf_standard()

sample.pdf is the sample file used in this example. Click here to download it.

Binary file (PDF, 36 KB)

Download full output

More resources

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online Apps

Along with the full-featured Python library, we provide simple but powerful free online apps.

To sign PDF, Word, Excel, PowerPoint, and other documents you can use the online apps from the GroupDocs.Signature App Product Family.