Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

DynaPDF Manual - Page 54

Previous Page 53   Index   Next Page 55

Digital Signatures
Page 54 of 750
the private key; this password must later be passed to the function CloseAndSignFile() or
CloseAndSignFileEx() if the file should also be encrypted. Enter now the file name and path of
the certificate file, finished! The result is a certificate file with the extension *.pfx, this file can
now be used to digitally sign PDF files.
Importing signed PDF files
Signed PDF files can only be changed, without invalidating an existing signature, when changes
are stored with an incremental update. An incremental update is a special way to modify a PDF
file; changes are appended to the end of the file, leaving its original contents intact. This
technique is required since altering any existing bytes in the file invalidates existing signatures.
However, incremental updates are not supported by DynaPDF that is the reason why only
empty signature fields can be imported. Because DynaPDF creates always a completely new
PDF file, it makes no sense to import existing signatures, they would always become invalid.
How to sign a PDF file?
Signing a PDF file with the internal signature handler of DynaPDF is quite easy; all you need is
a PKCS#12 certificate file. Instead of calling the function CloseFile() or CloseFileEx() after the
document was created, call either CloseAndSignFile() or CloseAndSignFileEx() if the file should
also be encrypted, finished! A digital signature is always stored in a signature field. If no
signature field was created beforehand, DynaPDF creates an invisible signature field on the first
page and stores the signature in this field.
If the PDF file should be signed with an external signature handler call CloseAndSignFileExt(),
sign the provided hash or byte ranges, and finally finish the signature with FinishSignature() to
insert the signed PKCS#7 object into the PDF file.
How to create a signature field?
As mentioned above, the function CloseAndSignFile() or CloseAndSignFileEx() creates an
invisible signature field on the first page if no signature field was already created or imported
beforehand. If the signature field should be visible, just create one with the function
CreateSigField() on the page where the field should appear. If multiple signature fields exist,
DynaPDF uses the last signature field to sign the PDF file.
How to modify the appearance of a signature field?
The appearance of a signature field can be fully user defined. The function CreateSigFieldAP()
can be used to create a user defined signature appearance template. You can draw anything you
want into this template such as images, vector graphics, text, and it is also possible to import a
PDF page into or to draw an EMF file into the template.

Previous topic: How to export a Windows Certificate?

Next topic: How to validate a signature?