AddSignature

Declaration

Delphi

function AddSignature(Page, x1, y1, x2, y2: Integer; const Name, Reason, Biodata: PAnsiChar; ShowNameAndDate: Boolean): Integer; stdcall;

ActiveX

HRESULT _stdcall AddSignature([in] long Page, [in] long x1, [in] long y1, [in] long x2, [in] long y2, [in] BSTR Name, [in] BSTR Reason, [in] BSTR Biodata, [in] VARIANT_BOOL ShowNameAndDate, [out, retval] long* RetVal);


Description

By using this method you can add a signature to the document. You will need to set the position of the signature by defining the top/left and bottom/right corners of the signature rectangle. You can also add signature details, which will be visible in the document (as optional stamp and in the signature details). As result you get an Integer value back.


AddSignature will force you to confirm the document hash on the device. In order to disable this necessity, you can enable the Emulation Mode (see Driver Options) before start signing.


AddSignature required the 4 Callback Event (OnGetAesKey, OnGetDeviceCertificate, OnGetSignedDocHash, OnReadHighResBitmap). Without them adding a Signature into a PDF is not possible.


Arguments

ArgumentDescription
PagePage is the number of the page in the PDF, on which the signature should be added.
X1,Y1These are the upper left coordinates of a rectangle on the page into which the signature shall be added.
X2,Y2The are the lower right coordinates of the rectangle (Hint: You can use GetPageSize to get the X and Y dimensions of the page). The provided rectangle does not necessarily have to fit the size of the subsequent signature, because the API is streching the signature in the correct x/y scale to fit it the best way into the given coordinates.
Name Name is the name of the signer and will be added to the signature details and into the optional stamp below the signature.
Reason Reason is the reason of signing, it will also be added into the signature details and the stamp.
BiodataBiodata is the biodata of the signature which you can get from the freeware deviceAPI (GetBiodataString or peekBiodataString).
showNameAndDateShowNameAndDate is for embedding the stamp under the signature. It contains the previously provided name, reason and time and is visible in the document and also in the signature details.


Return value

AddSignature returns the following integer values:

ValueMeaning
-29signature field is to small, height and width needs to be higher an 20
-28failure in imagestream from pad
-27the four needed events are not defined
-26the signatureimage is wrong
-25image file extention unknown
-24image file not exisiting
-23Image buffer is nil or size is 0
-22document is sealed oder hash is encrypted with unknown key
-21document erroneous
-20no document is loaded
-12temp file hash is incorrect
-11

No key(s)*

-10

Seal required*

-5Exception occured
-4Timeserver access error
-3Signing will be repeated
-2Signing was cancelled
-1Signature was not added to the document, because of an error
0

Unspecified result

1

Signature was successful added to the document

*obsolete


Calculation of the PDF coordinates

The top/left has the value 0/0 and for the calculation you can use the following formula:

A4= 8.27 x 11.69 inch with 72points/inch = 595x842 points

1 point = 0.03527777778 centimeters

1 point = 0.01388888889 inch

Example: 5cm are 142 points (5cm / 0.03527777778 = 141,7323)

 

Samples

C# - AddSignature
// Set device parameters
 
SignAPIv4.DeviceModel = SigDev.GetDriverString(0);
SignAPIv4.DeviceSerial = SigDev.GetDriverString(1); 
          
// Get biodata from device
             
string bd = "";
SigDev.peekBiodataString(ref bd);
            
// Add signature to document
           
int x1 = 100; 
int x2 = 250; 
int y1 = 100; 
int y2 = 200; 
int page = 1;
string signer = "John Doe";
string reason = "I agree with the content.";
bool showStamp = true;
 
int addResult = SignAPIv4.AddSignature(page, x1, y1, x2, y2, signer, reason, bd, showStamp);

switch(addResult)
{  
	case -11:	MessageBox.Show("No key(s).");
        		break;
                
	case -10: 	MessageBox.Show("Seal required.");
         		break;                     
       
 	case -3: 	MessageBox.Show("Repeat.");
         		break;    
              
 	case -2: 	MessageBox.Show("Cancelled.");			
         		break;                    
                
	case -1: 	MessageBox.Show("Error.");               
         		break;
                
	case 0: 	MessageBox.Show("Unspecified result.");                			
         		break;                      
                
 	case 1: 	MessageBox.Show("Succeeded.");                
         		break;
}
vb.net - AddSignature
'Set device parameters
'DeviceModel : This Property must be Set by the client application before calling AddSignature. 

SignatureAPI4.DeviceModel = SignatureDevice.GetDriverString(0)
SignatureAPI4.DeviceSerial = SignatureDevice.GetDriverString(1)  
 
'Get the biodata from the device
Dim bd As String = ""
SignatureDevice.peekBiodataString(bd)

Dim page, x1, y1, x2, y2, addResult As Integer
page = 1
x1 = 100
x2 = 250 
y1 = 100 
y2 = 200 
addResult = SignatureAPI4.AddSignature(page, x1, y1, x2, y2, "Name", "Reason", bd, True)

Select Case (addResult)

	Case -11
			MessageBox.Show("No key.")

	Case -10
			MessageBox.Show("Seal required.")

	Case -3
			MessageBox.Show("Repeat.")

	Case -2
			MessageBox.Show("Cancelled.")

	Case -1
			MessageBox.Show("Error.")

	Case 0
			MessageBox.Show("Unspecified result.")

	Case 1
			MessageBox.Show("Succeeded.")

End Select
Delphi- AddSignature
    SOPad.getBiodataString(Biodata);
    if Biodata <> '' then
    begin
        SOAPI4.DeviceModel  := SOPad.GetDriverString(0);
        SOAPI4.DeviceSerial := SOPad.GetDriverString(1);

        SOAPI4.SetDynamicStampText('Signed by: Mr. X<br>Reason: <b>Conformation of the Contract</b> if Contract<br>Time: <i>' + FormatDateTime('c',Now) +'</i>');

        SOAPI4.TimeCenterURL := 'http://stepoverinfo.net:88/tsa/'; // use empty string '' for no timeserver

        SOAPI4.addSignature(1, 100, 100, 250, 200, 'Mr X', 'Conformation', Biodata, True);
	end;