使用VBA宏将签名添加到PDF

时间:2020-11-03 23:23:54

标签: excel vba pdf adobe

我在将签名添加到Adobe PDF时遇到一些问题。由于某种原因,我无法使用附加代码将数字身份证添加到PDF中。

有什么建议吗?

我使宏正常工作,因此可以使用以下代码将其添加到“签名”字段中-

Sub Prepare_PDF()

On Error GoTo Err_Handler

Dim pdfPDDoc As New AcroPDDoc, oJS As Object, oFields, oAttachment As Object

Dim strFName As String

Dim strSignature As String

Dim strSignFName As String

Dim oParam As Parameter

strFName = "A:\Corporate\Data\Financial\YE2020\Utilities\Month 10\Journal Entries\Robert\PDF File\Cost Transfer - 70145173 - 0100771347.pdf"


'------- Add signature fields to PDF file----------

If pdfPDDoc.Open(strFName) Then

Set oJS = pdfPDDoc.GetJSObject

Set oFields = oJS.AddField("SignatureField1", "signature", 0, Array(200, 620, 450, 670))


'------- Save PDF file------------------

strFName = Left(strFName, Len(strFName) - 4) & "-signed.pdf"

pdfPDDoc.Save 1, strFName

End If

Exit_Proc:

    Exit Sub
       

Err_Handler:

    MsgBox "In test" & vbCrLf & Err.Number & "--" & Err.Description

    Resume Exit_Proc

End Sub

现在,当我添加此代码以添加我的数字ID时,该错误消失了。

Sub Prepare_PDF()

On Error GoTo Err_Handler

Dim pdfPDDoc As New AcroPDDoc, oJS As Object, oFields, oAttachment As Object

Dim strFName As String

Dim strSignature As String

Dim oPpklite As Object

Dim strSignFName As String

Dim oParam As Parameter

strFName = "A:\Corporate\Data\Financial\YE2020\Utilities\Month 10\Journal Entries\Robert\PDF File\Cost Transfer - 70145173 - 0100771347.pdf"

strSignature = "C:\Users\hanlonr\OneDrive - Aecon\Desktop\RobertHanlon.pfx"


'------- Add signature fields to PDF file----------

If pdfPDDoc.Open(strFName) Then

Set oJS = pdfPDDoc.GetJSObject

Set oFields = oJS.AddField("SignatureField1", "signature", 0, Array(200, 620, 450, 670))

Set oSign = oJS.GetField("SignatureField1")

Set oPpklite = oJS.security.getHandler("Adobe.PPKLite", True)
      oPpklite.login "{'Password', '" & strSignature & "'}"
      oSign.signatureSign oPpklite
      oPpklite.logout

'------- Save PDF file------------------

strFName = Left(strFName, Len(strFName) - 4) & "-signed.pdf"

pdfPDDoc.Save 1, strFName

End If

Exit_Proc:

    Exit Sub
       

Err_Handler:

    MsgBox "In test" & vbCrLf & Err.Number & "--" & Err.Description

    Resume Exit_Proc

End Sub

0 个答案:

没有答案