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

Trying to get my head around the trustedFunction method

StevenD
Registered: Oct 6 2006
Posts: 368

I'm just not getting this trustedFunction method. I have read the documentation in the Acrobat JavaScript reference and found an article by Thom Parker on using trusted functions. I'm not sure just what I should put in the body of the function.

I have two parts of a script. One creates templates from pages in the document and I know that this can only be done through batch, console or menu events. The second part of the script resets the Crop, Trim, and Bleed page boxes which I can do using a toolbar button. I have tried to put this whole script in the body of the trustedFunction but with no success.

Is there anything else I can read to explain how this method works?

I have this script working in a batch sequence and it works great. However I was hopeing to get it to work with a single button click instead of more mouse movement to get the to the batch sequence.

StevenD

My Product Information:
Acrobat Pro Extended 9.3.1, Windows
StevenD
Registered: Oct 6 2006
Posts: 368
I don't really understand where a script with trustedFunction method goes. Is it supposed to go in the JavaScript folder?

StevenD

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
It has to go in an application folder, either the Acrobat application or the user's application folder for Acrobat.

You can use the "app.getPath('app', 'javascript');" for the application folder location and "app.getPath('user', 'javascript');" to get the user application folder. You will have to use those commands in the JavaScript debugger.

George Kaiser

ChrisFreeman
Registered: May 6 2007
Posts: 19
I hope I am reading your question correctly. You might want to break the problem into two parts: Creating trusted functions and the creating the button functions you want.

First, create a JS file in the app JS folder (for global access) or user JS folder (for single user access) as mentioned by gkaiseril. In this JS file, create a trusted function for each of the functions you need. For Example, create the file StevenDTrustedFunctions.JS containing your trusted functions, such as:

trustedCreateTemplate = app.trustedFunction( function (param1, param2)
{
// Additional code may appear above
app.beginPriv(); // Explicitly raise privilege
// insert your template creation code here that needs preivileged execute
app.endPriv();
// Additional code may appear below.
})

You may wish to create several trusted functions each covering a separate code segment needing a raised execution privilege, such as app.newDoc(), doc.saveAs(), etc.

Second, in your code for your toolbar button, you can now reference each trusted function. For example, if your trustedCreateTemplate returned an object, then in your button code you could use code such as:

var myTemplate = trustedCreateTemplate( var1, var2 ); // assuming you need 2 variables.

Additionally, if your toolbar button code is JS and is also placed in the same folder as the trusted function code, then both the button code and the trusted function code can reside in the same file.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Also remember that if you use any function which is not a part of the app object, you will need to pass the parent object as a parameter as well.
For example, if you want to create a trusted function for doc.saveAs(), you can't use the "this" keyword. You need to pass doc itself as a parameter to your trusted function (as well as the new path, and any other parameters you might need).

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com