AddSignatureImage

Declaration

Delphi

function AddSignatureImage(Page, x1, y1, x2, y2: Integer; const Name, Reason, Location: PAnsiChar; ShowNameAndDate: Boolean; ImageBuffer: Pointer; BufferSize: Cardinal; Extra: Pointer): Integer; stdcall;

ActiveX

HRESULT _stdcall AddSignatureImage([in] long Page, [in] long x1, [in] long y1, [in] long x2, [in] long y2, [in] BSTR Name, [in] BSTR Reason, [in] BSTR Location, [in] VARIANT_BOOL ShowStamp, [in] VARIANT Image, [out, retval] long* RetVal);


Description

By using this method you can add an image to the document. This image is added as a digital signature to the PDF document, which allows you to add context to the PDF after you already signed it.


AddSignatureImage required the 4 Callback Event (OnGetAesKeyOnGetDeviceCertificateOnGetSignedDocHashOnReadHighResBitmap). 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.
Image

Image is the image you want to embed into the digital signature. The format must be a BMP file.


Return value

AddSignatureImage 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

1point = 0.01388888889 inch

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

Sample

C# - AddSignatureImage
// load the BMP file and save it into a MemoryStream        

Bitmap bmp = new Bitmap(@"C:\Users\ane\Desktop\test.bmp");          
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
 
// set Values for AddSignatureImage
 
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."; 
string location = "Stuttgart";
            
int result = SignAPIv4.AddSignatureImage(page, x1, y1, x2, y2, signer, reason, location, false, ms.ToArray());
vb.NET - AddSignatureImage
'load the BMP file And save it into a MemoryStream     

Dim bmp As Bitmap = New Bitmap("signature_image.bmp")
Dim MS As System.IO.MemoryStream = New System.IO.MemoryStream()
bmp.Save(MS, System.Drawing.Imaging.ImageFormat.Bmp)

Dim signer As String = "John Doe"
Dim reason As String = "I agree with the content."
Dim Location As String = "Stuttgart"
Dim page, x1, y1, x2, y2, addPic As Integer
page = 1
x1 = 100
x2 = 250 
y1 = 100 
y2 = 200 

addPic = SignatureAPI4.AddSignatureImage(page, x1, y1, x2, y2, signer, reason, Location, True, MS.ToArray())
 
Select Case (addPic)

	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