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);
}
}
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