# How to sign PDF document

## Description

I would like to sign newly created PDF document.

## Solution

The **DigitalSignature** method is used to add a digital signature to a PDF document. Prior to digitally signing a document, the users or developers should have on their systems a digital certificate that can be used to sign documents.

### Syntax

.DigitalSignature "Name of the signer", "Reason", "ImageFile", "Location", -1,0 ,0, 0 ,0 , 1 + 4 + 32

### Parameters

**SignerName**\
This is the friendly name of the digital signature as it appears to the user when the digital certificate is installed on the system. In most cases, this is the full name of the person signing the document.

**Reason**\
Reason for signing the document. Can be an empty string if no reason is specified.

**ImageFile**\
Full path of the file containing the image that is associated with the signature. This is optional, a digital signature does not always contain an image.

**Location**\
Physical location of the person who signed the document. This parameter is optional.

**PageNumber**\
Page number on which to insert the signature. Page numbers start with 1, the value -1 indicates the last page in the document.

**HorzPos, VertPos**\
Horizontal and vertical position of the digital signature in Twips.

**Width, Height**\
Width and height of the digital signature in Twips.

**Flags**\
Combination of flags that determine how the digial signature appears on the page. A value of 0 indicates that the signature is invisible.

### Return Value

This method returns 0 upon success, it returns one of the following exceptions upon failure:

E\_NOTIMPL The license key that is provided does not enable digital signatures

E\_ACCESSDENIED The document security settings do not allow the user to modify the document

E\_INVALIDARG One of the arguments is invalid or the certificate does not allow signing documents

E\_FAIL The signature already exists

### Remarks

The Flags parameter can be a combination of one of the following values:

Signer name                     1\
Reason for signing             2\
Location                           4\
Associated image              8\
Date of signing                  32\
Signature type                  64

### Code Example

`Sub Click(Source As Button)`

&#x20;           `Dim FilePathName As String`\
&#x20;           `Dim PDFApp As Variant`\
&#x20;           `Dim PDFDoc As Variant`\
&#x20;    \
&#x20;           `FilePathPDF = "C:\Temp\test.pdf"`\
&#x20;       \
&#x20;           `Set PDFDoc = CreateObject("cdintfex.document")`\
&#x20;       \
&#x20;           `With PDFDoc`\
&#x20;                       `.Open FilePathPDF`\
&#x20;                       `.SetLicenseKey SW_PDF_PRINTER_USER_NAME, SW_PDF_PRINTER_LICENSE_KEY`\
&#x20;                       `.DigitalSignature "Name of the signer", "Reason", "ImageFile", "Location", -1,0 ,0, 0 ,0 , 1 + 4 + 32`\
&#x20;                       `.Save "C:\Temp\signed_PDF.pdf"`\
&#x20;           `End With`\
&#x20;         \
`End Sub`

&#x20;Notice: Signer should have certificate on his/her name in the Windows digital ID repository. This name should be set as the first parameter in the .DigitalSignature method.
