The DigitalSignature and DocDigitalSignature methods are 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. This method requires a call to Document.SetLicenseKey before it can be used.
System.Boolean DigitalSignature(System.String SignedBy, System.String Reason, System.String ImageFile, System.String Location, System.int32 PageNumber, System.Int32 HorzPos, System.Int32 VertPos, System.Int32 Width, System.Int32 Height, System.Int32 Flags)
int DocDigitalSignature(EXTDOCHANDLE edhDocument, LPCSTR SignedBy, LPCSTR Reason, LPCSTR ImageFile, LPCSTR Location, long PageNumber, long HorzPos, long VertPos, long Width, long Height, long Flags)
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.
Item to show |
DLL Constants |
Value (Dec) |
Value (Hex) |
---|---|---|---|
Hidden Signature |
|
0 |
0x000 |
Signer name |
SIGNATURE_DISPLAY_SIGNER |
1 |
0x001 |
Reason for signing |
SIGNATURE_DISPLAY_REASON |
2 |
0x002 |
Location |
SIGNATURE_DISPLAY_LOCATION |
4 |
0x004 |
Associated image |
SIGNATURE_DISPLAY_IMAGE |
8 |
0x008 |
Certificate |
SIGNATURE_DISPLAY_CERTIFICATE |
16 |
0x010 |
Date of signing |
SIGNATURE_DISPLAY_DATE |
32 |
0x020 |
Signature type |
SIGNATURE_DISPLAY_TYPE |
64 |
0x040 |
Show All |
|
255 |
0x0FF |
Enabling PAdES |
SIGNATURE_LEVEL_PADES |
256 |
0x100 |
Enabling PAdES with LTV support (Long Term Validation) |
SIGNATURE_LEVEL_PADES_LTV |
512 |
0x200 |
edhDocument
Handle Returned by DocOpen.
The return value is True if the DigitalSignature method succeed. Otherwise, False If the DigitalSignature method fails.
The return value is zero if the DocDigitalSignature method succeed. If the DocDigitalSignature method fails, a negative value will returned, ex:
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. |
Member of CDIntfEx.Document.
<Flags()>
Public Enum DIGITALSIGNATURE 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
Public Sub Sample()
' Constants for Activation codes
Const strLicenseTo As String = "Amyuni PDF Converter Evaluation"
Const strActivationCode As String = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"
' Declare a new cdintfex document if it does not exist in the form.
Dim pdfDoc As New CDIntfEx.Document
' The SetLicenseKey method should be called after creating an object of type
' CDIntfEx.Document to activate the advanced methods that require the object
' activation code to work properly
pdfDoc.SetLicenseKey(strLicenseTo, strActivationCode)
' Open the document
pdfDoc.Open("c:\temp\test.pdf")
' Set Digital Signature
pdfDoc.DigitalSignature("Amyuni Dev Signature", "Testing", "c:\temp\signature.jpg",
"Montreal", 1, 100, 100, 400, 200, DIGITALSIGNATURE.SIGNATURE_DISPLAY_SIGNER Or
DIGITALSIGNATURE.SIGNATURE_DISPLAY_REASON Or DIGITALSIGNATURE.SIGNATURE_DISPLAY_LOCATION Or
DIGITALSIGNATURE.SIGNATURE_DISPLAY_IMAGE)
' Save the document
pdfDoc.Save("c:\temp\Signed.pdf")
End Sub
[Flags]
public enum DIGITALSIGNATURE
{
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
}
public void Sample()
{
// Constants for Activation codes
const string strLicenseTo = "Amyuni PDF Converter Evaluation";
const string strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA";
// Declare a new cdintfex document if it does not exist in the form.
CDIntfEx.Document pdfDoc = new CDIntfEx.Document();
// The SetLicenseKey method should be called after creating an object of type
// CDIntfEx.Document to activate the advanced methods that require the object
// activation code to work properly
pdfDoc.SetLicenseKey(strLicenseTo, strActivationCode);
// Open the document
pdfDoc.Open(@"c:\temp\test.pdf");
// Set Digital Signature
pdfDoc.DigitalSignature("Amyuni Dev Signature", "Testing", "c:\\temp\\signature.jpg",
"Montreal", 1, 100, 100, 400, 200, (int)(DIGITALSIGNATURE.SIGNATURE_DISPLAY_SIGNER |
DIGITALSIGNATURE.SIGNATURE_DISPLAY_REASON | DIGITALSIGNATURE.SIGNATURE_DISPLAY_LOCATION |
DIGITALSIGNATURE.SIGNATURE_DISPLAY_IMAGE));
// Save the document
pdfDoc.Save(@"c:\temp\Signed.pdf");
}
// PDF Converter Cpp.cpp : Defines the entry point for the console application.
//
#include <Windows.h>
#include <string>
#include <iostream>
#include "CdIntf.h"
#pragma comment (lib, "CDIntf.lib")
using namespace std;
int main()
{
// Constants for Activation codes
#define strLicenseTo "Amyuni PDF Converter Evaluation"
#define strActivationCode "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"
// Declare a new cdintfex document if it does not exist in the form.
EXTDOCHANDLE pdfDoc;
// The SetLicenseKey method should be called after creating an object of type
// CDIntfEx.Document to activate the advanced methods that require the object
// activation code to work properly
SetLicenseKeyA(strLicenseTo, strActivationCode);
// Open the document
LPBYTE passWord = nullptr;
DocOpenA(&pdfDoc, "c:\\temp\\test.pdf", passWord);
// Set Digital Signature
DocDigitalSignatureA(pdfDoc, "Amyuni Dev Signature", "Testing", "c:\\temp\\signature.jpg",
"Montreal", 1, 100, 100, 400, 200, SIGNATURE_DISPLAY_SIGNER |
SIGNATURE_DISPLAY_REASON | SIGNATURE_DISPLAY_LOCATION |
SIGNATURE_DISPLAY_IMAGE);
// Save the document
DocSaveA(pdfDoc, "c:\\temp\\Signed.pdf");
// Destroy pdfDoc object
DocClose(pdfDoc);
pdfDoc = nullptr;
return 0;
}
package Example;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class DigitalSignature {
public enum DIGITALSIGNATURE
{
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);
public int value;
public DIGITALSIGNATURE(int value)
{
this.value = value;
}
public Object value(){
return value;
}
}
public static void main(String[] args)
{
// Constants for Activation codes
String strLicenseTo = "Amyuni PDF Converter Evaluation";
String strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA";
// Declare a new cdintfex document if it does not exist in the form.
ActiveXComponent pdfDoc = new ActiveXComponent("CDIntfEx.Document.6.5");
// The SetLicenseKey method should be called after creating an object of type
// CDIntfEx.Document to activate the advanced methods that require the object
// activation code to work properly
Dispatch.call(pdfDoc, "SetLicenseKey", strLicenseTo, strActivationCode);
// Open the document
Dispatch.call(pdfDoc, "Open", "c:\\temp\\test.pdf");
// Set Digital Signature
Dispatch.call(pdfDoc, "DigitalSignature", "Amyuni Dev Signature", "Testing", "c:\\temp\\signature.jpg",
"Montreal", 1, 100, 100, 400, 200, DIGITALSIGNATURE.SIGNATURE_DISPLAY_SIGNER.value |
DIGITALSIGNATURE.SIGNATURE_DISPLAY_REASON.value | DIGITALSIGNATURE.SIGNATURE_DISPLAY_LOCATION.value |
DIGITALSIGNATURE.SIGNATURE_DISPLAY_IMAGE.value);
// Save the document
Dispatch.call(pdfDoc, "Save", "c:\\temp\\Signed.pdf");
// Destroy pdfDoc object
pdfDoc = null;
}
}
$DIGITALSIGNATURE = @{
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
}
# Constants for Activation codes
$strLicenseTo = "Amyuni PDF Converter Evaluation"
$strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"
#Declare a new cdintfex document if it does not exist in the form.
$pdfDoc = New-Object -ComObject CDIntfEx.Document.6.5
#The SetLicenseKey method should be called after creating an object of type
#CDIntfEx.Document to activate the advanced methods that require the object
#activation code to work properly
[System.__ComObject].InvokeMember('SetLicenseKey', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc, @($strLicenseTo, $strActivationCode))
#Open the document
[System.__ComObject].InvokeMember('Open', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc,"c:\temp\test.pdf")
#Set Digital Signature
[System.__ComObject].InvokeMember('DigitalSignature', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc,
@("Amyuni Dev Signature", "Testing", "c:\temp\signature.jpg", "Montreal", 1, 100, 100, 400, 200,
($DIGITALSIGNATURE::SIGNATURE_DISPLAY_SIGNER -bOr $DIGITALSIGNATURE::SIGNATURE_DISPLAY_REASON -bOr
$DIGITALSIGNATURE::SIGNATURE_DISPLAY_LOCATION -bOr $DIGITALSIGNATURE::SIGNATURE_DISPLAY_IMAGE)))
#Save the document
[System.__ComObject].InvokeMember('Save', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc,"c:\temp\Signed.pdf")
#Destroy pdfDoc object
$pdfDoc = $null
' DigitalSignature Flags
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
' Constants for Activation codes
Const strLicenseTo = "Amyuni PDF Converter Evaluation"
Const strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"
' Declare a new Document object
Dim pdfDoc
Set pdfDoc = CreateObject("CDIntfEx.Document.6.5")
' The SetLicenseKey method should be called after creating an object of type
' CDIntfEx.Document to activate the advanced methods that require the object
' activation code to work properly
pdfDoc.SetLicenseKey strLicenseTo, strActivationCode
' Open the document
pdfDoc.Open "c:\temp\test.pdf"
' Set Digital Signature
pdfDoc.DigitalSignature "Amyuni Dev Signature", "Testing", "c:\temp\signature.jpg",_
"Montreal", 1, 100, 100, 400, 200, SIGNATURE_DISPLAY_SIGNER Or _
SIGNATURE_DISPLAY_REASON Or SIGNATURE_DISPLAY_LOCATION Or _
SIGNATURE_DISPLAY_IMAGE
' Save the document
pdfDoc.Save "c:\temp\Signed.pdf"
' Destroy pdfDoc object
Set pdfDoc = Nothing