PDF In-Depth

Popup Menu Programming in Acrobat JavaScript

Basic Operation

Advertisement
 

 

Let's start off looking at the app.popUpMenu method. It's simpler and structurally both methods are identical, so everything we do with the easier to use method will apply to the other.

This method will take any number of arguments. Each argument is either a string or an array of strings. If we go with the simple case, strings only, we can create a single level list style menu. The menu items are the same as, and appear in the same order as the arguments to the popUpMenu function.

var result = app.popUpMenu("apple", "orange", "coconut", "mango");

Simple Menu

The popup menu methods are blocking functions. This means execution of the JavaScript stops at this line until the user either selects an item from the menu or cancels the selection. The value of the selected item is returned and placed in the result variable. If the user were to select apple from this menu, the value return to the variable result would then be apple. If the selection is canceled, null is returned.

To create a sub menu we'll replace one of the string arguments with an array of strings. The first element of the array is always the parent item and the following elements form the items of the submenu.

app.popUpMenu("apple", ["oranges", "navel", "valencia", "blood"],
  "coconut", "mango");

2-Level Menu

It is important to note that parent items cannot be selected from the menu and therefore cannot be returned by the popUpMenu method. In the example above, oranges is the only parent item in the menu and so it will never be returned. The sub menu items immediately below the parent item are called the child items, some of which may also be parent items as we'll see in the next example. Only menu items having no children can be returned from the popUpMenu method. These items are called leaves. This terminology is consistent with any hierarchical, or tree type structure.

Simple so far, but what if we want yet another level in the menu. Well, this is easy too. It's just an extension of what we have already done, i.e. replace any string, except the first element in an array, with an array of strings. Let's reorganize the menu from the previous example to try this out.

app.popUpMenu("apple",["citrus", ["oranges","navel","valencia"],
  ["grapefruit","pink","yellow"]]);

3-Level Menu

One last note on this topic. The first element of any array is always the parent element of a sub menu. If it is replaced with another array, or any other data type, the string representation of this value would still be the parent item. The results of such a replacement may be a funny looking and meaningless menu since none of the elements of the replacing item will contribute to the menu list.

PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Quick PDF Library

Get products to market faster with this amazing PDF developer SDK. Over 900 functions and an equally...

Download free demo

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
Platinum Sponsor





Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.

Features

Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.