Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

can't populate digital signature field in Adobe reader XI

Community Beginner ,
Nov 13, 2019 Nov 13, 2019

Copy link to clipboard

Copied

/*
 * 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 = "UNKNOWN";

/* 
 * path to the digital signature file
 *
 * to test the sample without user input, specify:
 * ACROSDK.sigDigitalIDPath = "/C/DrTest.pfx";
 */
ACROSDK.sigDigitalIDPath = "UNKNOWN";

// other variables the user can modify 
ACROSDK.sigHandlerName = "Adobe.PPKLite";
ACROSDK.sigFieldname = "sdkSignatureTest";
ACROSDK.sigReason = "I want to test my digital signature program.";
ACROSDK.sigLocation = "San Jose, CA";
ACROSDK.sigContactInfo = "sendme@testinc.com";

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:AddSignature", 
	cUser: "Add My Signature", 
	cParent: "ACROSDK:JSSubMenu", 
   cEnable: "event.rc = (event.target != null);",
   cExec: "AddSignature(event.target)"    
});


/**
 * main function
 */ 
function AddSignature(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 = AddSignatureField(doc);

	// sign it
	if(signatureField)	Sign(signatureField, ACROSDK.sigHandlerName);
}



/**
 * create a signature field in the upper left conner with name of ACROSDK.sigFieldname
 */
function AddSignatureField(doc)
{
	var inch=72;
	var aRect = doc.getPageBox( {nPage: 0} );
	aRect[0] += 0.5*inch; // from upper left hand corner of page.
	aRect[2] = aRect[0]+2*inch; // Make it 2 inch wide
	aRect[1] -= 0.5*inch;
	aRect[3] = aRect[1] - 0.5*inch; // and 0.5 inch high

	var sigField = null;
	try {
		sigField = doc.addField(ACROSDK.sigFieldname, "signature", 0, 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.signatureSign({oSig: myEngine, 
								bUI: false,
								oInfo: { password: ACROSDK.sigUserPwd, 
										reason: ACROSDK.sigReason,
										location: ACROSDK.sigLocation,
										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;
}

I placed the code above (I found it the Adobe Acrobat SDK website) in the 'javascipts' folder of my Adobe Reader XI installation folder. The two menus correctly appear under the edit menu. I provide the digital ID path and password but the signature field is blank eventually. I had the same result even when I hard coded the digital ID path and password. Any ideas?

TOPICS
Security digital signatures and esignatures

Views

692
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
community guidelines
LEGEND ,
Nov 13, 2019 Nov 13, 2019

Copy link to clipboard

Copied

1. Adobe Reader XI is obsolete and has unfixed security issues. Upgrading is free! Doesn't mean this is fixed, you may have worse issues than this.

2. First rule of JavaScript, check for errors. Please use Ctrl+J (or Command+J) to display the JavaScript console and tell us the messages you see.

3. Do you have any reason to believe this is meant to work with the free Reader? Almost all of the SDK is for paid-for Acrobat only.

Votes

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
community guidelines
Community Beginner ,
Nov 13, 2019 Nov 13, 2019

Copy link to clipboard

Copied

LATEST

I have just installed Acrobat pro Dc in trial mode. The result is the same. The javascript debugger issues the following warning 'An error occurred: GeneralError: Operation failed.'

Votes

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
community guidelines