I have been searching for an answer in different forums without success, so I decided to open a post.
Currently, I generate a PDF file from a range or a worksheet in Excel. What I need is to include a signature in the PDF file.
This is the code that I gather from different sources to open the PDF and sign it:
I do have Adobe Acrobat installed in my computer (not the free Acrobat Reader) and I added a reference to "Adobe Acrobat 10.0 Type Library" with the "acrobat.tlb" file.
The code aborts at the line with oSign.signatureSign. I can not make it run, because of this error: "TypeError: Invalid argument type". I tried different alternatives in that line, but none worked.
If I comment that line, the code created a rectangle with my signature on it, but it was not signed: if I open the PDF, and click on the signature, I can succesfully sign it. But I want to see if it can be automated from VBA.
Currently, I generate a PDF file from a range or a worksheet in Excel. What I need is to include a signature in the PDF file.
This is the code that I gather from different sources to open the PDF and sign it:
VBA Code:
Public Sub SignPDF()
On Error GoTo Err_Handler
Dim pdfPDDoc As New AcroPDDoc, oJS As Object, oSign As Object, oPpklite As Object, oFields As Object
Dim strFName As String, strSignFName As String
Dim oSignInfo As Object, strSecInfo As String
Dim oParam As Parameter
strSignFName = "C:\mySignature.pfx"
strFName = "C:\myPdf.pdf"
Set pdfPDDoc = CreateObject("AcroExch.PDDoc")
If pdfPDDoc.Open(strFName) Then
Set oJS = pdfPDDoc.GetJSObject
Set oFields = oJS.AddField("SignatureField", "signature", 0, Array(350, 800, 500, 750))
Set oSign = oJS.GetField("SignatureField")
Set oPpklite = oJS.security.getHandler("Adobe.PPKLite", True)
oPpklite.login "{'xxx', '" & strSignFName & "'}"
oSign.signatureSign oPpklite, "{password:xxx, mdp: allowNone}" , "C:\myPdfSigned.pdf", True
pdfPDDoc.Save 1, strFName
oPpklite.logout
End If
Exit_Proc:
Exit Sub
Err_Handler:
MsgBox "In test" & vbCrLf & Err.Number & "--" & Err.Description
Resume Exit_Proc
End Sub
I do have Adobe Acrobat installed in my computer (not the free Acrobat Reader) and I added a reference to "Adobe Acrobat 10.0 Type Library" with the "acrobat.tlb" file.
The code aborts at the line with oSign.signatureSign. I can not make it run, because of this error: "TypeError: Invalid argument type". I tried different alternatives in that line, but none worked.
If I comment that line, the code created a rectangle with my signature on it, but it was not signed: if I open the PDF, and click on the signature, I can succesfully sign it. But I want to see if it can be automated from VBA.