How can I use signatureSign to apply a Digital ID signature to every field in a document? (JavaScript)

I am trying to batch apply a signature to a document where I have already added fields to every page using the following code (starting on page 2):

var inch = 72;
for (var i = 1; i <= this.numPages; i++) {
var f = this.addField("Seal_Signature_Field" + i, "signature", i, [7.126*inch, 1.242*inch, 8.116*inch, 0.261*inch]);
}

This code executes correctly, creating signature fields titled "Seal_Signature_Field10", etc. My issue is when I attempt to apply a script that will add a signature to those fields on every page. The code I have is:

for (var i = 1; i <= this.numPages; i++) {
var ppklite = security.getHandler( "Adobe.PPKLite" );
ppklite.login( "XXXX", "/C/Users/XXXXX/Desktop/XXXXX.pfx" );
var f = this.getField(this.getNthFieldName(i));
f.signatureSign( ppklite, {password: "XXXX", appearance: "XXXX"} );
}

I have tested the code on a single sheet (removed for loop) with this.getField("Seal_Signature_Field1"), and it executes perfectly fine. But there's something with the f variable and how it's using signatureSign in the loop that is resulting in an error of:

"GeneralError: Operation failed.
Field.signatureSign:7:Batch undefined:Exec
The document could not be signed.

There was an error when attempting to commit this signature. The document was not saved.

The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder."

I know this is really basic JavaScript, but I am pulling my hair out trying to get it to work - Any help would be much appreciated.


Alexander Mezey


Voted Best Answer

Question has been solved, it was simply an error in the directory I was loading the document from.


By Alexander Mezey   


Please specify a reason: