Acrobat External Control Example

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
gpulawski
Newbie
Posts: 6
Joined: Mon Sep 10, 2007 3:11 am

Acrobat External Control Example

Post by gpulawski » Sun Sep 23, 2007 6:28 pm

I thought this might be useful to someone.

Using Adobe Acrobat it is possible to run an internal Acrobat Javascript from the outside using Macro Scheduler's VB Script.

An Example: Create a Javascript File containing the following (using notepad or something):

Code: Select all

//javascript file, at the folder level (trusted), adds a menu item to Acrobat Pro 6 that creates
// a digital signature field, signs it, and prints it to a printer.

// password to use the digital signature
var sigUserPwd = "theRealPassword";

// path to the digital signature file in Acrobat Device independant syntax
// (this one is on a windows C: drive root)
var sigDigitalIDPath = "/C/TheRealSignature.pfx";

// other variables the user can modify 
var sigHandlerName = "Adobe.PPKLite";
var sigFieldname = "Signature";
var sigReason = "I am the author.";
var sigLocation = "whereever USA";
var sigContactInfo = "[email protected]";


/* Add a menu item for AddSignature */
app.addMenuItem( { cName: "ADBESDK:AddSignature", cUser: "Add My Signature", cParent: "Advanced", 
  cEnable: "event.rc = (event.target != null);",
       cExec: "AddSignature(event.target)" });


// main function
function AddSignature(doc)
{
	// create a new signature field
	var signatureField = AddSignatureField(doc);

	// sign it
	Sign(signatureField, sigHandlerName);
	
	//Print it
	var myParams=this.getPrintParams();
	//set the printer
	myParams.printerName="whatever Printer name";
	//No print dialog
	myParams.interactive=2;
	//execute
	this.print(myParams);

}



// create a signature field in the upper left conner with name of 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(sigFieldname, "signature", 0, aRect );
	} catch (e) {
		console.println("An error occurred: " + e);
	}

	return sigField;
}


// sign PDF quietly using all predefined info or data
function Sign( sigField, DigSigHandlerName )
{
  try {
	var myEngine = security.getHandler(DigSigHandlerName); 
	myEngine.login( sigUserPwd, sigDigitalIDPath); 
	sigField.signatureSign({oSig: myEngine, 
							bUI: false,
							oInfo: { password: sigUserPwd, 
									reason: sigReason,
									location: sigLocation,
									contactInfo: sigContactInfo}
							});
  } catch (e) {
		console.println("An error occurred: " + e);
  }
}
Save this as a something.js file (after making the appropriate modifications to the paths and variables in the program) at the trusted folder level for Acrobat. It's usually Programs>Adobe>Acrobat6>Acrobat>Javascript or something like that. this javascript will place a new menu item on Acrobat 6 which will create a digital signature field, sign it, and print it.

Now, in Macro Scheduler you can trigger the menu item's associated Javascript directly using: (it will also put up a messagebox that will tell you the version of Acrobat you are running.)

Code: Select all

VBStart

dim formApp
set formApp = CreateObject("AFormAut.App")
dim fields
set fields=formApp.fields
dim nVersion
nVersion=fields.ExecuteThisJavascript("event.value = app.viewerVersion;")
MsgBox "The Acrobat Viewer Version is " & nVersion

dim menuItem
menuItem="ADBESDK:AddSignature"
jsCode="app.execMenuItem(" + "'" + menuItem + "');"
fields.ExecuteThisJavascript (jsCode)

VBEND


fornachari
Newbie
Posts: 1
Joined: Mon Feb 25, 2008 7:48 pm

Post by fornachari » Mon Feb 25, 2008 7:57 pm

gpulawski, Do you have this VB example in C#?

Thank in advance!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts