Adding custom menu commands in Acrobat 8

Learn some tips on adding interactive features to Acrobat 8 and PDF files.

By January 20, 2007

 

One of the great things I like about Acrobat is that it offers me freedom—for customizing the Acrobat workspace and for adding many dynamic, interactive actions to my PDF files. In this new series, I’ll share some tips on adding interactive features to Acrobat and PDF files.

In this first tip, I’ll start with the Acrobat 8.0 user interface. No matter how many new features Adobe adds to each new version, there’s always some little thing I’d like to add to the program to help me out when reviewing files from readers and when analyzing documents.

One of the things that helps me in this regard is adding custom menu commands. With Acrobat 8, I can add menu commands for a host of different features that aren’t coded in the program. Of particular interest are commands to help me analyze PDF forms. For example, I might want to know if a form contains one or more page templates and how many fields are contained within a PDF file. I could open a dialog box to view page templates and I can count fields on a page to obtain my results, but an easier and more efficient method is to simply add some menu commands to do the work for me.

Here’s how I add helpful menu commands to assess the number of page templates and form fields:

Use NotePad (Windows) or TextEdit (Macintosh) and type the following JavaScript code in a new document window:

function totalFields(){
	app.alert("Total Fields:" + this.numFields);
}
function totalTemplates(){
	app.alert("Total Page Templates:" + this.numTemplates);
}
app.addMenuItem ({cName: "Number of Fields", cParent: "Tools", cExec: "totalFields()" });
app.addMenuItem ({cName: "Page Templates", cParent: "Tools", cExec: "totalTemplates()" });

Save the file as text only with a .js extension. In my example, I saved the file as tools.js. Copy this file to the Acrobat JavaScripts folder. (Note that you should use a text editor and not a word processor for creating the script).

On Windows, the path is: C:/Program Files/Adobe/Acrobat 8.0/Acrobat/JavaScripts.

On the Mac the path is: Macintosh HD/Users/Logon Name/Library/Acrobat User Data/8.0_x86/JavaScripts. (note that 8.0_x86 is found on Intel Macs. PPCs will have 8.0 for the folder name).

If Acrobat is open, quit the program and relaunch it. Open a file and select the Tools menu. You should see two new menu commands added to the bottom of the menu, as shown in Figure 1.

Figure 1

Select the Number of Fields menu command and an application-alert dialog box opens, reporting the number of fields on the currently opened document -- as you can see in Figure 2. The second menu item works the same way and reports the number of page templates.

These menu commands are particularly helpful when you want to analyze a password-protected PDF document. You may open a file with hidden fields and/or page templates. Without having access to the Advanced Editing tools and editing forms, you can’t locate hidden fields or open the Page Templates dialog box. However, the menu commands report the number of fields/templates, regardless of whether they are visible or hidden on secured PDFs.

These are just two of many different types of menu commands you can add to Acrobat to customize the user interface according to your personal preferences. For more information on adding menu commands, refer to the following scripting reference.

Acrobat JavaScript Scripting Reference

Download [PDF: 7.1 MB]

Stay tuned to AcrobatUsers.com for more tips on adding interactivity to PDF documents. In forthcoming articles, I’ll talk about adding application-popup menus, creating popup menus to navigate documents in PDF packages, transposing form data, creating application-response dialog boxes and more.

Read more Acrobat 8 tips from Ted Padova in the "Adobe Acrobat 8 PDF Bible," available from Amazon.


Did you know?

  • You can ask a question and get an answer from one of our experts.
  • You can search our database of over 800 tutorials by product and/or topic.
  • You can leave a comment below for the author of this tutorial.

Related topics:

JavaScript

Top Searches:

Edit PDF, create PDF, Action Wizard

0 comments

Comments for this tutorial are now closed.

Comments for this tutorial are now closed.