Digital Signature - Javascript - General Error: Opertion Failed
I've used the below code for ~7 years, but have recently been getting the following error: "An error occurred: GeneralError: Operation failed.", in the console, but unfortunately, this is all the console shows, so I have been unable to troubleshoot and determine what is causing the error. All I know is that the signature field gets placed correctly, but the signature is not being applied.
Any help is appreciated.
Thanks!
/*
* sdkAddSignature.js
*
*
* Folder Javascript Created by Acrobat SDK.
* This JavaScript sample shows you can programmatically sign a PDF document using
* your digital ID file.
*
* As a sample, this file has included all the digital signature information
* except the path and password for the digital ID file to be used.
* When you are ready to sign a PDF, click the newly added "Add My Signature"
* menu item under the Edit>Acrobat SDK JavaScript menu.
*
* After you input the platform independent path and
* the password through a dialog, the program will create a digital
* signature field in the top-left corner, and sign it with your data. The path
* and password are valid in a Acrobat session, so you can continue to sign more
* documents in the session without the input dialogs.
* If you change the code to specify the path and password for the digital ID
* file to be used in this file, then when you click the menu item, the program will
* go automatically to sign PDFs without UI.
*
* Using the function SetUserPassword() and function SetUserDigitalIDPath() in this
* folder JavaScript code, you can call the JavaScript to quietly sign a PDF from other
* JavaScript code, or from a plug-in or IAC VB or VC program through function
* ExecuteThisScript( ). The VB and C Sample code is attached in end of this file.
*
* A digital signature file ( DrTest.pfx ) is provided with the sample for your test
* To use it, put it in a folder, and specify the proper DIpath ( e.g. /C/DrTest.pfx ).
* Its password is "testpassword".
*/
/*
* Use of an object to emulate a unique namespace.
*
* Object literals act like global variables
* defined within this particular namespace.
*/
if (typeof ACROSDK == "undefined")
var ACROSDK = {};
/*
* password to use the digital signature
*
* to test the sample without user input, specify:
* ACROSDK.sigUserPwd = "testpassword";
*/
ACROSDK.sigUserPwd = "password";
/*
* path to the digital signature file
*
* to test the sample without user input, specify:
* ACROSDK.sigDigitalIDPath = "/C/DrTest.pfx";
*/
ACROSDK.sigDigitalIDPath = "/G/My Drive/Digital Certificate/Date_Name.pfx";
// other variables the user can modify
ACROSDK.sigHandlerName = "Adobe.PPKLite";
ACROSDK.sigFieldname = "SignatureField";
ACROSDK.sigLocation = "City, State";
ACROSDK.sigContactInfo = "email";
if ( typeof sdkMenuItem == "undefined")
var sdkMenuItem = false;
if (!sdkMenuItem) {
sdkMenuItem = true;
app.addSubMenu( {
cName:"ACROSDK:JSSubMenu",
cUser: "Acrobat SDK JavaScript",
cParent: "Edit",
nPos: 0
});
}
// Add a menu item for AddSignature
app.addMenuItem( {
cName: "ACROSDK:AddSignatureFL",
cUser: "Add Digital Signature - FL",
cParent: "ACROSDK:JSSubMenu",
cEnable: "event.rc = (event.target != null);",
cExec: "AddSignatureFL(event.target)"
});
/**
* main function
*/
function AddSignatureFL(doc)
{
// if ACROSDK.sigDigitalIDPath is not spcified, ask for user input
if(ACROSDK.sigDigitalIDPath == "UNKNOWN"){
var cResponse = app.response({
cQuestion: "Input your digital ID path:",
cTitle: "Digital Signature",
cDefault: "/C/DrTest.pfx",
});
if ( cResponse == null) {
app.alert("No input.");
return;
}
else
SetUserDigitalIDPath(cResponse);
}
// if ACROSDK.sigUserPwd is not spcified, ask for user input
if(ACROSDK.sigUserPwd == "UNKNOWN"){
var cResponse = app.response({
cQuestion: "Input your password:",
cTitle: "Digital Signature",
cDefault: "testpassword",
});
if ( cResponse == null) {
app.alert("No input.");
return
}
else
SetUserPassword(cResponse);
}
// create a new signature field
var signatureField = AddSignatureFieldFL(doc);
// sign it
if(signatureField) Sign(signatureField, ACROSDK.sigHandlerName);
}
/**
* create a signature field in the upper left conner with name of ACROSDK.sigFieldname
*/
function AddSignatureFieldFL(doc)
{
var inch=72;
var aRect = doc.getPageBox( {nPage: 0} );
aRect[0] += 14.26*inch; // from upper left hand corner of page.
aRect[2] = aRect[0]+1.75*inch; // Make it 1.75 inch wide
aRect[1] -= 3.81*inch;
aRect[3] = aRect[1] - 0.6*inch; // and 0.6 inch high
var sigField = null;
try {
sigField = doc.addField(ACROSDK.sigFieldname, "signature", this.pageNum, aRect );
} catch (e) {
console.println("An error occurred: " + e);
}
return sigField;
}
/**
* define the Sign function as a privileged function
*/
Sign = app.trustedFunction (
function( sigField, DigSigHandlerName )
{
try {
app.beginPriv();
var myEngine = security.getHandler(DigSigHandlerName);
myEngine.login( ACROSDK.sigUserPwd, ACROSDK.sigDigitalIDPath);
sigField.signatureSetSeedValue({appearanceFilter: "FL", flags: 256});
sigField.signatureSign({oSig: myEngine,
bUI: false,
oInfo: { password: ACROSDK.sigUserPwd,
contactInfo: ACROSDK.sigContactInfo}
});
app.endPriv
} catch (e) {
console.println("An error occurred: " + e);
}
}
);
/**
* set a correct password for using the signature, so you can quietly sign a doc.
*/
function SetUserPassword(pwd)
{
ACROSDK.sigUserPwd = pwd;
}
/**
* set path to the digital signature file
*/
function SetUserDigitalIDPath(idPath)
{
ACROSDK.sigDigitalIDPath = idPath;
}
