These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

using javascript in a plugin.

Tim Klahr
Registered: Feb 7 2011
Posts: 12
Answered

Hello,
 
I am using a plugin called automailmerge created by evermap. It's fairly straight forward as far as filling in fields, sending an email, etc. Where I am stuck is at the javascript part. It offers you to run javascript code before or after the mail merge is run. Basically all I want to do is attach a pdf to each mail merged document. Ideally the pdf to attach would be chosen by the number of the purchase order (ex. 12004.pdf), but one thing at a time. I am getting notallowederror when trying to run:
 
this.insertPages({nPage:this.numPages-1,
cPath:"PO12004.pdf"});
 
In the console this works fine, and adds the pdf to the end of the document. However, when I use that code in the plugin, I recieve a notallowederror. I have tried to use a trustedfuction, with no success. I even added the code below to the config.js file that I've seen on this forum and others.
 
var insertPO = app.trustedFunction( function (cPath)
{
app.beginPriv();
this.insertPages({nPage:this.numPages-1,
cPath:"PO12004.pdf"});
app.endPriv();
}
);
 
Do any of you have any ideas on how to get this code to run in a plugin? Or do you have any suggestions on what I should use to do a automated mail merge?
 
Thanks for your time,
 
Tim

My Product Information:
Acrobat Pro 9.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Accepted Answer
The plug-in is running the JavaScript in the context of the document. It's as if the script was being run from a button on the PDF. So the trusted function is the way to go. Put your code in the trusted function and then call the trusted function from the script. For testing purposes, place the calling code into a button on the PDF. When you get it to work there you can use the same code in the plug-in script.


There is a potential problem with your code. The cPath parameter in the insertPages call should be the full path to the file. If Acrobat does not find the file it will throw a security exception. Rather unhelpful, but that's Acrobat.



Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script