DigitalSignature Method

The DigitalSignature method is used to add a digital signature to a PDF document. Users or developers should have on their systems a digital certificate that can be used to sign documents.

 

Syntax

VB:

Sub DigitalSignature(SignerName As String, Reason As String, ImageFile As String, Location As String, PageNumber As Integer, HorzPos As Integer, VertPos As Integer, width As Integer, height As Integer, flags As Integer)

C#:

void DigitalSignature(string SignerName, string Reason, string ImageFile, string Location, int PageNumber, int HorzPos, int VertPos, int width, int height, int flags)

C++:

HRESULT DigitalSignature(BSTR SignerName, BSTR Reason, BSTR ImageFile, BSTR Location, long PageNumber, long HorzPos, long VertPos, long Width, long Height, long Flags)

 

See Also the Signature object.

 

Parameters

SignerName

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; it 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 where the document was signed. This parameter is optional.

PageNumber

It is the 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

It is the Horizontal and vertical position of the digital signature in Twips.

Width, Height

It is the Width and height of the digital signature in Twips.

Flags

It is a combination of flags that determine how the digital signature appears on the page. A value of 0 indicates that the signature is invisible. Flags parameter can be a combination of one of the following values:

 

Flags

Value

(Dec)

Value

(Hex)

Hidden Signature

0

0x000

Signer name

1

0x001

Reason for signing

2

0x002

Location

4

0x004

Associated image

8

0x008

Certificate

16

0x010

Date of signing

32

0x020

Signature type

64

0x040

Show all

255

0x0FF

Enabling PAdES

256

0x100

Enabling PAdES with LTV support

 (Long Term Validation)

512

0x200

 

 

Return Value

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

 

Option

Description

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

Of the arguments is invalid or the certificate does not allow signing documents.

E_FAIL

The signature already exists.

 

 

Remarks

 

This method uses the DefaultFont attribute of the Document Object for the texts.

 

Example

<Flags()>

Public Enum FlagsSignature As Integer

    SIGNATURE_DISPLAY_SIGNER = &H1

    SIGNATURE_DISPLAY_REASON = &H2

    SIGNATURE_DISPLAY_LOCATION = &H4

    SIGNATURE_DISPLAY_IMAGE = &H8

    SIGNATURE_DISPLAY_CERTIFICATE = &H10

    SIGNATURE_DISPLAY_DATE = &H20

    SIGNATURE_DISPLAY_TYPE = &H40

    SIGNATURE_LEVEL_PADES = &H100

    SIGNATURE_LEVEL_PADES_LTV = &H200    

End Enum

 

Sub Sample()

    ' Constants for Activation codes

    Const strLicenseTo As String = "Amyuni PDF Creator Evaluation"

    Const strActivationCode As String = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC"

 

    ' Initializing PDFCreativeX Object

    Dim pdf As ACPDFCREACTIVEX.PDFCreactiveX = New ACPDFCREACTIVEX.PDFCreactiveX()

 

    ' Set license key

    pdf.SetLicenseKey(strLicenseTo, strActivationCode)

 

    ' Set CurrentPage

    pdf.CurrentPage = 1

 

    ' Create a Text in the current Page

    pdf.CreateObject(ACPDFCREACTIVEX.ObjectTypeConstants.acObjectTypeText, "Text1")

 

    ' Define obj as Text1

    Dim oText As ACPDFCREACTIVEX.IacObject = pdf.GetObjectByName("Text1")

 

    ' Set-up the Text

    oText("Left") = 1000

    oText("Right") = 5000

    oText("Top") = 0

    oText("Bottom") = 4000

    oText("BorderColor") = &HFF00FF

    oText("BorderWidth") = ACPDFCREACTIVEX.acBorderWidth.acBorderWidthDouble

    oText("Text") = "Amyuni Technologies"

 

    ' Add digital signature

    Dim signedBy As String = "Test User"

    Dim reason As String = "Testing"

    Dim imageFile As String = "C:\temp\signature.png"

    Dim location As String = "Montreal"

    Dim pageNumber As Integer = 1

    Dim horzPos As Integer = 4000

    Dim vertPos As Integer = 4500

    Dim width As Integer = 6000

    Dim height As Integer = 6000

    Dim flags As Integer = FlagsSignature.SIGNATURE_DISPLAY_SIGNER Or FlagsSignature.SIGNATURE_DISPLAY_IMAGE

    pdf.DigitalSignature(signedBy, reason, imageFile, location, pageNumber, horzPos, vertPos, width, height, flags)

 

    ' Save PDF

    pdf.Save("c:\temp\CreatePDFDocument_resulting.pdf", ACPDFCREACTIVEX.FileSaveOptionConstants.acFileSaveView)

 

 

    oText = Nothing

End Sub

[Flags]

enum FlagsSignature

{

    SIGNATURE_DISPLAY_SIGNER = 0x001,

    SIGNATURE_DISPLAY_REASON = 0x002,

    SIGNATURE_DISPLAY_LOCATION = 0x004,

    SIGNATURE_DISPLAY_IMAGE = 0x008,

    SIGNATURE_DISPLAY_CERTIFICATE = 0x010,

    SIGNATURE_DISPLAY_DATE = 0x020,

    SIGNATURE_DISPLAY_TYPE = 0x040,

    SIGNATURE_LEVEL_PADES = 0x100,

    SIGNATURE_LEVEL_PADES_LTV = 0x200

}

 

static void Sample()

{

    // Constants for Activation codes

    const string strLicenseTo = "Amyuni PDF Creator Evaluation";

    const string strActivationCode = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC";

 

    // Initializing PDFCreativeX Object

    ACPDFCREACTIVEX.PDFCreactiveX pdf = new ACPDFCREACTIVEX.PDFCreactiveX();

 

    // Set license key

    pdf.SetLicenseKey(strLicenseTo, strActivationCode);

 

    // Set CurrentPage

    pdf.CurrentPage = 1;

 

    // Create a Text in the current Page

    pdf.CreateObject(ACPDFCREACTIVEX.ObjectTypeConstants.acObjectTypeText, "Text1");

 

    // Define obj as Text1

    ACPDFCREACTIVEX.IacObject oText = pdf.GetObjectByName("Text1");

 

    // Set-up the Text

    oText["Left"] = 1000;

    oText["Right"] = 5000;

 

    oText["Top"] = 0;

    oText["Bottom"] = 4000;

    // Text Attributes

    oText["BorderColor"] = 0xFF00FF;

    oText["BorderWidth"] = ACPDFCREACTIVEX.acBorderWidth.acBorderWidthDouble;

    oText["Text"] = "Amyuni Technologies";

 

    // Add digital signature

    string signedBy = "Test User";

    string reason = "Testing";

    string imageFile = @"C:\temp\signature.png";

    string location = "Montreal";

    int pageNumber = 1;

    int horzPos = 4000;

    int vertPos = 4500;

    int width = 6000;

    int height = 6000;

    int flags = (int)(FlagsSignature.SIGNATURE_DISPLAY_SIGNER | FlagsSignature.SIGNATURE_DISPLAY_IMAGE);

    pdf.DigitalSignature(signedBy, reason, imageFile, location, pageNumber, horzPos, vertPos, width, height, flags);

 

    // Save PDF

    pdf.Save(@"c:\temp\CreatePDFDocument_resulting.pdf", ACPDFCREACTIVEX.FileSaveOptionConstants.acFileSaveView);

 

 

    oText = null;

}

#include <iostream>

#import "c:\users\amyuni\pdfcreactivex.dll" no_namespace

 

using namespace std;

 

enum FlagsSignature

{

    SIGNATURE_DISPLAY_SIGNER = 0x001,

    SIGNATURE_DISPLAY_REASON = 0x002,

    SIGNATURE_DISPLAY_LOCATION = 0x004,

    SIGNATURE_DISPLAY_IMAGE = 0x008,

    SIGNATURE_DISPLAY_CERTIFICATE = 0x010,

    SIGNATURE_DISPLAY_DATE = 0x020,

    SIGNATURE_DISPLAY_TYPE = 0x040,

    SIGNATURE_LEVEL_PADES = 0x100,

    SIGNATURE_LEVEL_PADES_LTV = 0x200

};

 

int main()

{

    // Constants for Activation codes

    bstr_t strLicenseTo = "Amyuni PDF Creator Evaluation";

    bstr_t strActivationCode = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC";

 

    // Initialize the COM subsystem

    CoInitialize(0);

 

    // IPDFCreactiveXPtr is a smart pointer type defined in pdfcreactivex.tlh,

    // the type library header file generated by the #import instruction above

    IPDFCreactiveXPtr pdf;

 

    // Create the PDFCreactiveX instance

    pdf.CreateInstance(__uuidof(PDFCreactiveX));

 

    // set license key

    pdf->SetLicenseKey(_bstr_t(strLicenseTo), _bstr_t(strActivationCode));

 

    // Set CurrentPage

    pdf->CurrentPage = 1;

 

    // Set-up variables for attributes

    _variant_t varAttribute;

    varAttribute.vt = VT_I4;  // integers

 

                              // Create a text in the current Page

    pdf->CreateObject(acObjectTypeText, "Text1");

 

    // Define Object

    IacObjectPtr oText = pdf->GetObjectByName("Text1");

 

    // General Attributes

    oText->Attribute["Left"] = 1000;

    oText->Attribute["Right"] = 3250;

    oText->Attribute["Top"] = 0;

    oText->Attribute["Bottom"] = 500;

    // Text Attributes

    varAttribute.lVal = 0xFF00FF;

    oText->Attribute["BorderColor"] = varAttribute;

    varAttribute.lVal = acBorderWidthDouble;

    oText->Attribute["BorderColor"] = varAttribute;

    oText->Attribute["Text"] = "Amyuni Technologies";

 

    // Add digital signature

    bstr_t signedBy = "Test User";

    bstr_t reason = "Testing";

    bstr_t imageFile = "C:\\temp\\signature.png";

    bstr_t location = "Montreal";

    int pageNumber = 1;

    int horzPos = 4000;

    int vertPos = 4500;

    int width = 6000;

    int height = 6000;

    int flags = (int)(SIGNATURE_DISPLAY_SIGNER | SIGNATURE_DISPLAY_IMAGE);

    pdf->DigitalSignature(signedBy, reason, imageFile, location, pageNumber, horzPos, vertPos, width, height, flags);

 

    // Save PDF

    pdf->Save("c:\\temp\\CreatePDFDocument_resulting.pdf", acFileSaveView);

 

    // destroy objects

    pdf = NULL;

    oText = NULL;

 

    return 0;

}

' FlagsSignature

Const SIGNATURE_DISPLAY_SIGNER = 1

Const SIGNATURE_DISPLAY_REASON = 2

Const SIGNATURE_DISPLAY_LOCATION = 4

Const SIGNATURE_DISPLAY_IMAGE = 8

Const SIGNATURE_DISPLAY_CERTIFICATE = 16

Const SIGNATURE_DISPLAY_DATE = 32

Const SIGNATURE_DISPLAY_TYPE = 64

Const SIGNATURE_LEVEL_PADES = 256

Const SIGNATURE_LEVEL_PADES_LTV = 512

 

' ObjectTypeConstants

Const acObjectTypeArrow = 36

Const acObjectTypeBarcode = 45

Const acObjectTypeCell = 33

Const acObjectTypeCheckBox = 21

Const acObjectTypeEllipse = 4

Const acObjectTypeExcel = 17

Const acObjectTypeField = 6

Const acObjectTypeGraph = 19

Const acObjectTypeHighlight = 23

Const acObjectTypeLine = 1

Const acObjectTypePicture = 7

Const acObjectTypePolygon = 8

Const acObjectTypeRoundFrame = 3

Const acObjectTypeRow = 32

Const acObjectTypeSelection = 24

Const acObjectTypeSignature = 39

Const acObjectTypeStickyNote = 22

Const acObjectTypeTable = 16

Const acObjectTypeText = 5

 

' acBorderWidth

Const acBorderWidthNone = 0

Const acBorderWidthSimple = 1

Const acBorderWidthDouble = 2

Const acBorderWidthTriple = 3

Const acBorderWidthQuadruple = 4

 

' FileSaveOptionConstants

Const acFileSaveAll = 0

Const acFileSaveDefault = -1

Const acFileSaveView = 1

Const acFileSaveDesign = 2

Const acFileSavePDFA_7 = 3

Const acFileSavePDFA = 4

Const acFileSavePDF14 = 5

 

' Constants for Activation codes

Const strLicenseTo = "Amyuni PDF Creator Evaluation"

Const strActivationCode = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC"

 

' Initializing PDFCreativeX Object

Dim pdf

Set pdf = CreateObject("PDFCreactiveX.PDFCreactiveX.6.5")

 

' Set license key

pdf.SetLicenseKey strLicenseTo, strActivationCode

 

' Set CurrentPage

pdf.CurrentPage = 1

 

' Create a Text in the current Page

pdf.CreateObject acObjectTypeText, "Text1"

 

' Define Object

Dim oText 

Set oText = pdf.GetObjectByName("Text1")

 

' General Attributes

oText("Left") = 1000

oText("Right") = 5000

oText("Top") = 0

oText("Bottom") = 4000

' Text Attributes

oText("BorderColor") = &HFF00FF

 

oText("BorderWidth") = acBorderWidthDouble

oText("Text") = "Amyuni Technologies"

 

' Add digital signature

Dim signedBy

signedBy = "Test User"

Dim reason

reason= "Testing"

Dim imageFile

imageFile = "C:\temp\signature.png"

Dim location1 

location1 = "Montreal"

Dim pageNumber

pageNumber = 1

Dim horzPos

horzPos = 4000

Dim vertPos 

vertPos = 4500

Dim width 

width = 6000

Dim height 

height = 6000

Dim flags

flags= SIGNATURE_DISPLAY_SIGNER Or SIGNATURE_DISPLAY_IMAGE

pdf.DigitalSignature signedBy, reason, imageFile, location1, pageNumber, horzPos, vertPos, width, height, flags

 

' Save PDF using StartSave, SavePage and EndSave

pdf.Save "c:\temp\CreatePDFDocument_resulting.pdf", acFileSaveView

 

' destroy Objects

Set pdf = Nothing

Set oText = Nothing