How can I digitally sign a document using JavaScript?
As part of a bigger product I need to programatically sign some PDFs using Adobe Acrobat. I have a physical USB token connected, and manually I would do the following:
"Use a certificate" -> "Digitally sign" -> draw the field with the mouse -> select the Digital ID from the list (only one) -> "Continue" -> "Sign" -> "save" on the windows pop up
I have come up with the following code to set up the signature field and try to sign:
var pageWidth = 612;
var pageHeight = 792;
var signatureWidth = 100;
var signatureHeight = 50;
var padding = 10;
var left = pageWidth - signatureWidth - padding;
var bottom = pageHeight - signatureHeight - padding;
var f = this.addField("mySignature", "signature", 0, [left, bottom, left + signatureWidth, bottom + signatureHeight]);
var ppklite = security.getHandler("Adobe.PPKLite");
var sigField = this.getField("mySignature");
sigField.signatureSign(ppklite);but the response I get is:
Exception in line 13 of function top_level, script Console:Exec
GeneralError: Operation failed.
Field.signatureSign:13:Console undefined:Exec
[ Creation of this signature could not be completed. ] -> [ You have not selected a valid digital ID. Try again. ]
After trying to figure out using the oficial documentation and some unofficial examples, I have to say I am stumped, as most examples use the `login` function by passing a .pfx file, which I do not know of existing. Any ideas as to how I can automate this process I can do manually?
