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 (OnGetAesKey, OnGetDeviceCertificate, OnGetSignedDocHash, OnReadHighResBitmap). Without them adding a Signature into a PDF is not possible. |
Arguments
Argument | Description |
---|---|
Page | Page is the number of the page in the PDF, on which the signature should be added. |
X1,Y1 | These are the upper left coordinates of a rectangle on the page into which the signature shall be added. |
X2,Y2 | The 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. |
Biodata | Biodata is the biodata of the signature which you can get from the freeware deviceAPI (GetBiodataString or peekBiodataString). |
showNameAndDate | ShowNameAndDate 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:
Value | Meaning |
---|---|
-29 | signature field is to small, height and width needs to be higher an 20 |
-28 | failure in imagestream from pad |
-27 | the four needed events are not defined |
-26 | the signatureimage is wrong |
-25 | image file extention unknown |
-24 | image file not exisiting |
-23 | Image buffer is nil or size is 0 |
-22 | document is sealed oder hash is encrypted with unknown key |
-21 | document erroneous |
-20 | no document is loaded |
-12 | temp file hash is incorrect |
-11 | No key(s)* |
-10 | Seal required* |
-5 | Exception occured |
-4 | Timeserver access error |
-3 | Signing will be repeated |
-2 | Signing was cancelled |
-1 | Signature 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
// 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());
'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