locked
How to make a signed pdf of document in Visual Basic RRS feed

  • Question

  • I have two kind of documents (normal pdf and an Excel file) that I need to [save as] a signed pdf document.

    In Excel I have in a cell the link to a pdf.

    I want to open this pdf and save it as a signed pdf with a signature (for example with the letters "MB").

    Is it possible to do this with Visual Basic Excel.

    I know how to open and save a pdf, but I can't find the option of signing the pdf with initiatials.

    Thank you upfront for any input.

    With kind regards, Marcel

    Thursday, December 29, 2016 3:59 PM

All replies

  • Hi MarcelStartVB,

    you had mentioned that you have a link in excel file.

    do you mean you want to open that linked pdf file programmatically and add a signature in that file?

    in Excel file you can add it like mentioned below.

    Sub demo()
    Dim objSignature As Object
    Set objSignature = ActiveWorkbook.Signatures.AddSignatureLine("{00000000-0000-0000-0000-000000000000}")
    objSignature.Setup.SuggestedSigner = "MB"
    objSignature.Setup.SuggestedSignerEmail = "Demo@xyz.com"
    objSignature.Setup.SuggestedSignerLine2 = "Demo line"
    
    
    End Sub
    

    Reference:

    Workbook.Signatures Property (Excel)

    if you are saving the Excel file as pdf then add signature first then convert it to pdf.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 30, 2016 2:22 AM
  • Dear Deepak,

    Thank you for thinking along.

    The situation is somewhat different (sorry if wrote the problem not clear enough).

    I have in a cell a link to a pdf document.

    1) I have to open that pdf document

    2) Add initials (for example "MB") to it

    3) Save the pdf, so it is saved with "-signed.pdf" in the filename (that will always be the case when initials are added to a pdf.

    So the problem is how to add initials to a pdf document with VBA-code in Excel.

    Regards, Marcel

    Friday, December 30, 2016 3:09 PM
  • Hi MarcelStartVB,

    I try to find examples that can add the signature in PDF file from excel but I did not find any helpful example. all examples are available for excel (.xlsx) file or any other MS Office products.

    I find one example from Adobe website may help you.

    you can try to have a look.

    Public Sub test()
    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:\Documents and Settings\638423\Ncts\AdobeSignature\testing.pfx"
                
        strFName = "C:\main.pdf"
        
        If pdfPDDoc.Open(strFName) Then
            Set oJS = pdfPDDoc.GetJSObject
            
            Set oFields = oJS.AddField("SignatureField", "signature", 0, Array(50, 750, 300, 700)) 'array(uplf, lwlf, lwrt, uprt)
            Set oSign = oJS.getField("SignatureField")
            
            Set oPpklite = oJS.Security.getHandler("Adobe.PPKLite", True)
            oPpklite.login "{'xxyy', '" & strSignFName & "'}"
    
            oSign.signatureSign oPpklite, "{password:xxyy, mdp: allowNone}", "C:\MainSigned.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
    

    you need to find the dll files from Adobe websites and needs to add the reference in your code and try to run the code from Excel Application.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 2, 2017 5:17 AM