The following will demonstrate on how to use the Aloaha digital signature API to sign a PDF document. Please note that we use in this example the error event to detect any possible errors while signing.
You might have seen that we supply even the Smarcard PIN. That is only possible with native supported cards such as the T-Systems Telesec, Infineon SiCrypt , german health cards and others.
If you use as function name sign_file instead then you can also pass as infile a NON PDF document. Aloaha will create as outfile an enveloped PKCS7 file. It is suggested to give the outfile the extension p7m.
Please contact our support department if you have questions regarding the Aloaha signature API or if you requiere an evaluation key.
To use the sample code please create an empty form in your VB6 project and create a button called “sign”. The aloahapdf objects needs to be referenced as well!
Dim WithEvents pdf As aloahapdf.edit
Private Sub Sign_Click()
On Error Resume Next
Dim reason As String
Dim location As String
Dim infile As String
Dim outfile As String
Dim cert As String
‘define signature reason
reason = “I created this document”
‘define signator location
location = “I am in the office”
‘use native supported smartcard in first cardreader
cert = “0”
‘define inputfile
infile = “c:\pdf\input.pdf”
‘define outputfile
outfile = “c:\pdf\output.pdf”
‘load, sign and unload
Set pdf = New aloahapdf.edit
‘text signatures work only if in Aloaha settings
‘incremental signatures have been disabled
‘HKCU\Software\Aloaha\pdf\ForceIncrementalSignature = 0
pdf.signaturecontent = “Signed at@@lf@@@@date@@@@lf@@with @@signature@@’s digital certificate.@@lf@@No further signature necessary.”
‘pdf.PIN = “250620”
Call pdf.sign_pdf_file(CStr(infile), CStr(outfile), 0, 0, 0, 0, 0, 0, CStr(reason), CStr(location), CStr(cert), “”)
If pdf.sign_pdf_file_returnstring <> “” Then
‘Problem while signing!
MsgBox pdf.sign_pdf_file_returnstring
End If
Set pdf = Nothing
End Sub
Private Sub pdf_LastErrorMessage(errormessage As String)
‘display errors
MsgBox errormessage
End Sub