Using Javascript to insert a digital signature

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Post Reply
oli78
User
Posts: 7
Joined: Wed Feb 14, 2018 3:43 am

Using Javascript to insert a digital signature

Post by oli78 »

Hi,

Apologies if this has been covered elsewhere - my googfu is failing me. I have a two step process, which I'm trying to automate.

Step one is working fine - inserting a series of signature fields when the pdf is created, in preparation for signing by various people. I launch the javascript console (ctrl-J), and do the following:

var f = this.addField("Designer","signature", 0, [1656,165,1752,146]);
var f = this.addField("Reviewer", "signature", 0, [1656,108,1758,87]);
var f = this.addField("Approveer", "signature", 0, [1656,127,1758,107]);

Save & Exit - works great.

Step two involves multiple people reviewing, and signing the pdf. This could be for many pdfs at once, and each person has a role. I'd like to be able to open a group of files, and run a "SignAsDesigner" script, and have them all signed in the appropriate location. Each person has a signature created, for simplicity lets call it "FullSignature"

/ insert dodgy pseudocode

for each open pdf
var f = this.getField("Designer");
f.signatureSign(insert magic here);
save the pdf
next

I can not for the life of me work out what to put in the "signaturesign" section to make it place nice.
Any suggestions please? Is this even possible with the javascript console, or do I need to look into the SDK, or some other mechanism?

Thanks,
AO
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17948
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Using Javascript to insert a digital signature

Post by Tracker Supp-Stefan »

Hello AO,

On page 454 of this document:
https://www.adobe.com/content/dam/acom/ ... erence.pdf
You can find thiis sample code:

Code: Select all

var myEngine = security.getHandler( "Adobe.PPKLite" );
myEngine.login( "dps017", "/c/profile/dps.pfx" );
var f = this.getField("Signature");

// Sign the field
f.signatureSign( myEngine, 
  { password: "dps017", // provide password
    location: "San Jose, CA", // ... see note below
    reason: "I am approving this document",
    contactInfo: "dpsmith@example.com",
    appearance: "Fancy"});
So can you please test with such details at your end and see if it works?

Regards,
Stefan
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Using Javascript to insert a digital signature

Post by Sasha - Tracker Dev Team »

Hello AO,

Also, here's a link to the web page of the JS help:
https://help.adobe.com/livedocs/acrobat ... sible=true

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
oli78
User
Posts: 7
Joined: Wed Feb 14, 2018 3:43 am

Re: Using Javascript to insert a digital signature

Post by oli78 »

Tracker Supp-Stefan wrote:Hello AO,

On page 454 of this document:
https://www.adobe.com/content/dam/acom/ ... erence.pdf
You can find thiis sample code:

Code: Select all

var myEngine = security.getHandler( "Adobe.PPKLite" );
myEngine.login( "dps017", "/c/profile/dps.pfx" );
var f = this.getField("Signature");

Stefan[/quote]

Hi Stefan,

I've seen this, and similar. I get failure at the first line when running the javascript console.
var myEngine = security.getHandler( "Adobe.PPKLite" );
"ReferenceError: security is not defined"

Is security something that isn't implemented perhaps?

Cheers,
AO
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Using Javascript to insert a digital signature

Post by Sasha - Tracker Dev Team »

Hello AO,

Have you tried executing this script in the Acrobat?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
oli78
User
Posts: 7
Joined: Wed Feb 14, 2018 3:43 am

Re: Using Javascript to insert a digital signature

Post by oli78 »

Hi Alex,

Yes.
The "var myEngine = security.getHandler( "Adobe.PPKLite" );" code is actually used in a script that we've used successfully in Acrobat in the past. Our organisation is in the process of migrating to PDF Xchange (which I'm quite pleased about), so I'm working to create similar functionality. I'm not sure if it's something I'm missing, or if there's certain functionality that isn't present.

Anything that references the security object seems to fail, e.g. (from the pdf linked, section titled "Digitally signing PDF Documents") to show the available security handlers.
for (var i=0; i<security.handlers.length; i++)
console.println(security.handlers);

I've tried on a few different machines, and Version 6.x and 7.x of PDF Xchange editor.

Any ideas?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Using Javascript to insert a digital signature

Post by Sasha - Tracker Dev Team »

Hello AO,

I just checked, and it seems that the "security" is not yet implemented in our JS engine.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
oli78
User
Posts: 7
Joined: Wed Feb 14, 2018 3:43 am

Re: Using Javascript to insert a digital signature

Post by oli78 »

Thanks Alex, at least I know now it isn't me. Is it on the roadmap with an ETA for future development by any chance?

Is there a way of accessing the Document --> Signing menu from javascript as an alternative?
User avatar
TrackerSupp-Daniel
Site Admin
Posts: 8611
Joined: Wed Jan 03, 2018 6:52 pm

Re: Using Javascript to insert a digital signature

Post by TrackerSupp-Daniel »

Hi Oli,
I don't believe so, the only reference I can find to calling the signature function requires calling security first, which we've sadly established doesn't work yet...

If you can find a way please do let us know so we can share it with others :)

as for a roadmap, I also do not have any ETA on it, know that it is a feature we plan to begin implementing in the future though.
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Post Reply