SignFile
Security and Signatures
Description
Applies a digital signature to a PDF document on disk
The signing identity must be in PKCS#12 format, holding a certificate and private key. The signed output is buffered in memory and only written to OutputFileName once signature generation has succeeded, so an existing destination file survives if validation or signing fails
Syntax
Delphi
Function TPDFlib.SignFile(Const InputFileName, OpenPassword, SignatureFieldName, OutputFileName, PFXFileName, PFXPassword, Reason, Location, ContactInfo: WideString): Integer;
ActiveX
Function PDFlib::SignFile(InputFileName As String, OpenPassword As String, SignatureFieldName As String, OutputFileName As String, PFXFileName As String, PFXPassword As String, Reason As String, Location As String, ContactInfo As String) As Long
DLL
int DLSignFile(int InstanceID, const wchar_t* InputFileName, const wchar_t* OpenPassword, const wchar_t* SignatureFieldName, const wchar_t* OutputFileName, const wchar_t* PFXFileName, const wchar_t* PFXPassword, const wchar_t* Reason, const wchar_t* Location, const wchar_t* ContactInfo);
int DLSignFileA(int InstanceID, const char* InputFileName, const char* OpenPassword, const char* SignatureFieldName, const char* OutputFileName, const char* PFXFileName, const char* PFXPassword, const char* Reason, const char* Location, const char* ContactInfo);
Parameters
| InputFileName | The path and file name of the input PDF to sign |
|---|---|
| OpenPassword | The optional password to open the input PDF if it is encrypted |
| SignatureFieldName | The name of the signature field to sign. If a field with this name does not exist it will be created. This field cannot be blank |
| OutputFileName | The path and file name of the signed PDF that should be created. This should be a different file to InputFileName. If in place signing is required (overwriting the original file) then this parameter should be left blank |
| PFXFileName | The path and name of the PKCS#12 certificate/private key file (.pfx file) |
| PFXPassword | The password to open the PFX file |
| Reason | An optional string indicating the reason for signing |
| Location | An optional string indicating the location that the signing was done |
| ContactInfo | An optional string indicating the contact information of the signer |
Return values
| 1 | The file was signed successfully |
|---|---|
| 2 | Input PDF not found |
| 3 | Input PDF cannot be read |
| 4 | Input PDF password incorrect |
| 5 | Certificate file not found |
| 6 | Certificate file is invalid |
| 7 | Incorrect certificate password |
| 8 | Unknown certificate format |
| 9 | No private key found in certificate file |
| 10 | Could not write output file |
| 11 | Could not apply signature |
| 12 | The signature field name was blank |
Remarks
The signature is written with the adbe.pkcs7.detached SubFilter and a SHA-256 digest (ISO 32000-1 12.8.3.3), as current validators expect; ISO 32000-2 deprecates the older adbe.pkcs7.sha1 form. To produce that form for a legacy validator, use the sign process functions with SetSignProcessSubFilter.