DynaPDF Manual - Page 225

Previous Page 224   Index   Next Page 226

Function Reference
Page 225 of 860
This function finishes the PDF file, encrypts it, digitally signs it, and frees all used resources if the
file was not created in memory. The first five parameters have the same meaning as of the function
CloseFileEx(). The remaining parameters are identical to CloseAndSignFile(). This function simply
combines both functions because a PDF file must be encrypted and digitally signed in one pass. The
encryption parameters are described in detail under CloseFileEx().
The parameter CertFile must be a valid path to a PKCS#12 certificate file. DynaPDF supports
certificate files with 1024 bits encrypted private keys only. The parameter Password holds the
password to decrypt the private key. The parameters Reason and Location are both optional. These
strings are printed into the signature field if set.
Digital signatures are stored in a signature field which is a special type of Interactive Form field. If
no signature field exist when the function is called then DynaPDF creates an invisible signature
field. Hidden signature fields appear in the signatures tab of Adobe's Acrobat.
If one or more signature fields exist when the function is called then the first signature field is used
for signing. Signature fields can be created with the function CreateSigField() but it is also possible
to import empty signature fields from an external PDF file.
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 why only empty signature
fields are imported. Because DynaPDF creates always a completely new PDF file, it makes no sense
to import existing signatures, they would become invalid.
Possible function errors
When trying to sign a PDF file the function must first parse the certificate file before a signature can
be created. This process can fail, due to an invalid file path or due to an unsupported certificate file
format that was passed to the function. The PDF file will be closed and signed if the certificate file
was valid and no other error occurred during the parsing process of the certificate file.
If an error occurred during the parsing process, e.g. invalid certificate file, invalid file path and so
on, the function returns zero and passes an error message to the error callback function if any. All
errors during the parsing process of the certificate file are non-fatal so that the PDF file is still in
memory when the function returns. It is then possible to change the certificate file and trying to sign
the PDF file again.
To determine whether the PDF was already deleted or of it is still in memory call the function
HaveOpenDoc(). The function returns true if the PDF file is in memory. If the function returns false,
the last error was fatal and the PDF file has already been deleted.
 

Previous topic: Possible function errors, CloseAndSignFileEx

Next topic: CloseAndSignFileExt