Digitally signing a pdf in using Excel VBA

Jan 10, 2018

Copy link to clipboard

Copied

I have a script that successfully populates data from Excel into a form I have created and saves it.  However, I'm having difficulty digitally signing the form.  The following is old code I found from previous literature and it seems like it should work but it has not yet.  Thanks!

            strSignFName = "C:\misc\Test.pfx"

            Set oSign = objJSO.getField("Test")

'            Set oSign = objJSO.getField("Pool Manager Signature")

            Set oPpklite = objJSO.Security.getHandler("Adobe.PPKLite", True)

          

            oPpklite.login "Test123", "C:\misc\Test.pfx"

            oSign.signatureSign oPpklite

            oPpklite.logout  

          

            'Create the output path, which will be like C:\Users\Christos\Desktop\Forms\01) First Name Last Name.pdf.

            strPDFOutPath = "S:\XXXXX\YYYY\FPU_" & wsF.Cells(i, 7).Value & ".pdf"

          

            'Save the form as new PDF file.

            objAcroPDDoc.Save 1, strPDFOutPath

I don't have any first hand experience with trying to sign from within VBA (or at least I don't remember if I ever tried), but my experience is that there are some features that cannot be automated via the JSObject, and you will have to write some folder level JavaScript with a function that performs the operation in question, and then call that function from within your VBA code. This may be a case where this is necessary.

TOPICS
Acrobat SDK and JavaScript

Views

3.7K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Digitally signing a pdf in using Excel VBA

Jan 10, 2018

Copy link to clipboard

Copied

I have a script that successfully populates data from Excel into a form I have created and saves it.  However, I'm having difficulty digitally signing the form.  The following is old code I found from previous literature and it seems like it should work but it has not yet.  Thanks!

            strSignFName = "C:\misc\Test.pfx"

            Set oSign = objJSO.getField("Test")

'            Set oSign = objJSO.getField("Pool Manager Signature")

            Set oPpklite = objJSO.Security.getHandler("Adobe.PPKLite", True)

          

            oPpklite.login "Test123", "C:\misc\Test.pfx"

            oSign.signatureSign oPpklite

            oPpklite.logout  

          

            'Create the output path, which will be like C:\Users\Christos\Desktop\Forms\01) First Name Last Name.pdf.

            strPDFOutPath = "S:\XXXXX\YYYY\FPU_" & wsF.Cells(i, 7).Value & ".pdf"

          

            'Save the form as new PDF file.

            objAcroPDDoc.Save 1, strPDFOutPath

I don't have any first hand experience with trying to sign from within VBA (or at least I don't remember if I ever tried), but my experience is that there are some features that cannot be automated via the JSObject, and you will have to write some folder level JavaScript with a function that performs the operation in question, and then call that function from within your VBA code. This may be a case where this is necessary.

TOPICS
Acrobat SDK and JavaScript

Views

3.7K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jan 10, 2018 0
Jan 10, 2018

Copy link to clipboard

Copied

I don't have any first hand experience with trying to sign from within VBA (or at least I don't remember if I ever tried), but my experience is that there are some features that cannot be automated via the JSObject, and you will have to write some folder level JavaScript with a function that performs the operation in question, and then call that function from within your VBA code. This may be a case where this is necessary.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 10, 2018 1
Jan 10, 2018

Copy link to clipboard

Copied

If it doesn't work a thing to check is the JavaScript console. Anything there?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 10, 2018 0
Jan 10, 2018

Copy link to clipboard

Copied

Just checked the JS Console.  These were the messages.  Suprised that it says the digital ID is not valid because I have no issue manually signing with this ID.

GeneralError: Operation failed.

Field.signatureSign:0:

[ Creation of this signature could not be completed. ] -> [ You have not selected a valid digital ID. Try again. ]

GeneralError: Operation failed.

Field.signatureSign:0:

[ Creation of this signature could not be completed. ] -> [ You have not selected a valid digital ID. Try again. ]

GeneralError: Operation failed.

SecurityHandler.login:0:

Missing required parameter(s) error

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 10, 2018 0
Jan 10, 2018

Copy link to clipboard

Copied

I would suggest working out the JS code you need for this operation by working in the Console Window, then as Karl suggested, placing it into a folder level function, and calling it from the VBA.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 10, 2018 0
Jan 10, 2018

Copy link to clipboard

Copied

I agree with Thom and Karl that I should setup the scripts in Acrobat and call it from VB.   I was originally playing with the SDK signature javascript example but now I think that solution didnt work because I didn't properly setup the functions in Acrobat first.   I will work with that.  Thanks for your time! 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 10, 2018 1