Resources
How To Articles
by Thom Parker of WindJack Solutions.Copyright © 2004 by WindJack Solutions Some
Notes on Developing Folder Level JavaScript
Folder (or plug-in) level scripts are text files containing JavaScript code and having the .js file extension. Acrobat looks for and loads these scripts on startup from two locations in the file system. These locations are system dependent, but can be easily identified by executing the following code from the JavaScript Console Window.
The main difficulty in developing a
folder level script is that it is necessary to restart Acrobat
when you want to load and test new code, a very time consuming
operation. For this
reason it is best to adopt a method that reduces the number of
times you will have to restart Acrobat.
In order for folder level code to be used
for task automation it must be made available to the user
through a UI element. There are two such elements in Acrobat,
Menu Items and Toolbar Buttons. A Menu Item is by far the
simplest to implement since it only requires a single line of
code. This line of code places an item named Hello on the File menu in Acrobat. When this menu item is selected by the user the folder level function HelloWorldProc is called. In the JavaScript file, the HelloWorldProc function is defined first and the app.addMenuItem line is the last one in the file. Here is the complete file function HelloWorldProc() Toolbar Buttons are a much more desirable UI element because they are easily recognizable and immediately available, i.e. no menu walking. Another advantage specific to JavaScript created Toolbar Buttons is they can be made much larger than the standard Acrobat Toolbar Buttons and are not restricted to a square shape. But they do have two drawbacks. First, code executed from a toolbar button has about the same security restrictions as document level JS. Mostly, this restriction includes operations that might be used in a malicious way, like document, page, and template creation. This situation really isn't that serious since most of the Acrobat JS methods don't require high security and if the code you are writing does require high security, the button could simply act as a front for a menu item, giving you the advantages of both a menu item and a toolbar button together. The second draw back is that a Toolbar Button requires JS Code to create the icon to be displayed on the button face. Specifying this icon is quite difficult and poorly documented in the Acrobat JS documentation. If you are interested in creating your own Toolbar Buttons you should consider purchasing AcroButtons, which is the only tool currently available for creating and managing JS Toolbar buttons. It is also very helpful in other ways for developing folder level scripts. There is another tool, which is not intended specifically for creating JS icon data, but can be used for this purpose. That tool is PDF CanOpener. Good luck and send us any comments you have on this article. thomp@windjack.com | |