IacDocument.DigitalSignature Method

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.

A user who receives a document that is digitally signed can verify if the digital signature is valid and if the document has been tempered with.

 

Syntax

Visual Basic .NET:

Public Function DigitalSignature(signedBy 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) As Boolean

C#:

public bool DigitalSignature(string signedBy , string reason , string imageFile , string location , int pageNumber , int horzPos , int vertPos , int width , int height , int flags)

 

Parameters

signedBy

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 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 digital signature appears on the page. A value of 0 indicates that the signature is invisible.

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

Returns Value True if the call succeeded and False otherwise.

The exception Amyuni.PDFCreator.IacException.LicenseKeyError might be generated if the provided license is not valid or wrong.

 

Remarks

 

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

 

Member of Amyuni.PDFCreator.IacDocument.

 

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 .NET Evaluation"

    Const strActivationCode As String = "07EFCDAB0100010025C3B7B351579FF94C49112EAF7368612744C7237C2F6A215A53E83A9ECCFFE54C52063CB05338BDE555773D7B1B"

 

    ' Initialize library

    ' This should be done once

    acPDFCreatorLib.Initialize()

 

    ' set license key This is needed only with licensed version

    acPDFCreatorLib.SetLicenseKey(strLicenseTo, strActivationCode)

 

    ' Create a new PDF document

    Dim doc As New Amyuni.PDFCreator.IacDocument()

 

    ' Create page object

    Dim page As Amyuni.PDFCreator.IacPage

 

    ' Define first page of PDF document

    page = doc.GetPage(1)

 

    ' Switch to design mode before adding objects to the document

    doc.ReportState = Amyuni.PDFCreator.IacReportState.acReportStateDesign

 

    ' Create a Text

    With page.CreateObject(Amyuni.PDFCreator.IacObjectType.acObjectTypeText, "Text1")

        .Attribute("Left").Value = 1000

        .Attribute("Top").Value = 0

        .Attribute("Right").Value = 3250

        .Attribute("Bottom").Value = 500

        .Attribute("Text").Value = "Amyuni Technologies"

        .Attribute("Single line").Value = True

    End With

 

    ' Switch to run mode after objects to the document

    doc.ReportState = Amyuni.PDFCreator.IacReportState.acReportStateRun

 

    ' 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

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

 

    ' Create new stream object

    Dim fileWrite As System.IO.Stream = System.IO.File.OpenWrite("C:\temp\CreatePDFDocument_resulting.pdf")

 

    ' Save stream

    doc.Save(fileWrite, Amyuni.PDFCreator.IacFileSaveOption.acFileSaveView)

 

    ' Close the stream

    fileWrite.Close()

 

    ' terminate library to free resources

    acPDFCreatorLib.Terminate()

 

    ' destroy objects

    doc.Dispose()

    page.Dispose()

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 .NET Evaluation";

    const string strActivationCode = "07EFCDAB0100010025C3B7B351579FF94C49112EAF7368612744C7237C2F6A215A53E83A9ECCFFE54C52063CB05338BDE555773D7B1B";

 

    // Initialize library

    // This should be done once

    acPDFCreatorLib.Initialize();

 

    // set license key This is needed only with licensed version

    acPDFCreatorLib.SetLicenseKey(strLicenseTo, strActivationCode);

 

    // Create a new PDF document

    Amyuni.PDFCreator.IacDocument doc = new Amyuni.PDFCreator.IacDocument();

 

    // Create page object

    Amyuni.PDFCreator.IacPage page;

 

    // Define first page of PDF document

    page = doc.GetPage(1);

 

    // Switch to design mode before adding objects to the document

    doc.ReportState = Amyuni.PDFCreator.IacReportState.acReportStateDesign;

 

    // Create a Text

    using (Amyuni.PDFCreator.IacObject oText = page.CreateObject(Amyuni.PDFCreator.IacObjectType.acObjectTypeText, "Text1"))

    {

        oText.Attribute("Left").Value = 1000;

        oText.Attribute("Top").Value = 0;

        oText.Attribute("Right").Value = 3250;

        oText.Attribute("Bottom").Value = 500;

        oText.Attribute("Text").Value = "Amyuni Technologies";

        oText.Attribute("Single line").Value = true;

    }

 

    // Switch to run mode after objects to the document

    doc.ReportState = Amyuni.PDFCreator.IacReportState.acReportStateRun;

 

    // Encryption

    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);

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

 

    // Create new stream object

    System.IO.FileStream fileWrite = new System.IO.FileStream(@"C:\temp\CreatePDFDocument_resulting.pdf",

    System.IO.FileMode.Create,

    System.IO.FileAccess.Write,

    System.IO.FileShare.Read);

 

    // Save stream

    doc.Save(fileWrite, Amyuni.PDFCreator.IacFileSaveOption.acFileSaveView);

 

    // Close the stream

    fileWrite.Close();

 

    // terminate library to free resources

    acPDFCreatorLib.Terminate();

}