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:
Create new instance of Signature class and pass source document path as a constructor parameter.
This example shows how to sign PDF document with several e-signatures as metadata.
fromdatetimeimportdatetimefromgroupdocs.signatureimportSignaturefromgroupdocs.signature.optionsimportMetadataSignOptionsfromgroupdocs.signature.domainimportPdfMetadataSignaturedefsign_pdf():withSignature("sample.pdf")assignature:options=MetadataSignOptions()# Add metadata signatures with values of different typesoptions.add(PdfMetadataSignature("Author","Mr.Scherlock Holmes"))# textoptions.add(PdfMetadataSignature("CreatedOn",datetime.now()))# date and timeoptions.add(PdfMetadataSignature("DocumentId",123456))# whole numberoptions.add(PdfMetadataSignature("SignatureId",123.456))# floating-point number# Sign the document and save the resultresult=signature.sign("signed.pdf",options)print(f"Signed with {len(result.succeeded)} metadata signature(s):")foriteminresult.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.
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.
fromdatetimeimportdatetime,timedeltafromgroupdocs.signatureimportSignaturefromgroupdocs.signature.optionsimportMetadataSignOptionsfromgroupdocs.signature.domainimportPdfMetadataSignaturesdefsign_pdf_standard():withSignature("sample.pdf")assignature:options=MetadataSignOptions()# Copy the standard PDF metadata signatures with new valuesnow=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 onceoptions.signatures.add_range(signatures)# Sign the document and save the resultresult=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.