Discuss this help topic in SecureBlackbox Forum

PDF: Sign PDF document

First load the document as described in the corresponding how-to article.

Add the signature to the document using AddSignature() method of TElPDFDocument class. The method returns the index of the newly added signature. Access this signature using Signatures[] property of TElPDFDocument class. The property returns an object of TElPDFSignature type.
You can reuse an existing signature field (when it's empty). To do this, find the signature field in EmptySignatureFields[] property and pass the index of the field to AddSignature() method.

Create an instance of TElPDFPublicKeySecurityHandler class, and assign a reference of the newly created instance to Handler property of the added signature.
PDF format supports two types of public key signatures - PKCS#1 and PKCS#7 signatures. The type is specified using SignatureType of TElPDFPublicKeySecurityHandler class (don't mix this property with the property of TElPDFSignature class, which has the same name, but different meaning).

Assign the storage with certificates, used for signing, to CertStorage property of TElPDFPublicKeySecurityHandler class. You can include one certificate or the whole certificate chain. The latter is desired, since the validation will not be performed correctly if the part of the chain is missing.

It is necessary to specify the so-called custom name of the security handler. This name is used by Acrobat and Reader to look for the certificates when validating the certificates. "Adobe.PPKLite" causes Adobe tools to look for certificates in internal storage. "Adobe.PPKMS" causes Adobe tools to look for certificates in Windows Certificate storage.

Next, adjust signature properties. You can set the author name using AuthorName property of TElPDFSignature class and specify the time using SigningTime property of TElPDFSignature class. For visible signatures specify the properties of the signature widget using WidgetProps property of TElPDFSignature class.

An important step is to specify the signature type. To create the document signature, set SignatureType property of TElPDFSignature class to stDocument and set Inivisible property of TElPDFSignature class to false or true depending on whether you want the signature to be visible or not. If you want to create MDP signature, set SignatureType to stMDP and Invisible property to false. MDP signatures are outdated and not recommended for use.

You can timestamp the signature using TSP (timestamping protocol). See more about timestamping of PDF documents in the corresponding how-to article.

Save and close the document using Close() method. The signing is performed when the document is saved.

How To articles about PDF signing

Discuss this help topic in SecureBlackbox Forum