10
Modifying the User Interface
Adding Navigation to PDF Documents
For example, the code shown below labels 10 pages within a document using the following
scheme:
i, ii, ii, 1, 2, 3, 4, 5, Appendix-A, Appendix-B:
// Pages 0-2 will have lower case roman numerals i, ii, iii:
this.setPageLabels(0, ["r", "", 1]);
// Pages 3-7 will have decimal numbering 1-5:
this.setPageLabels(3, ["D", "", 1]);
// Pages 8-9 will have alphabetic numbering:
this.setPageLabels(8, ["A", "Appendix-", 1]);
// The page labels will be printed to the console:
var labels = this.getPageLabel(0);
for (var i=1; i<this.numPages; i++)
labels += ", " + this.getPageLabel(i);
console.println(labels);
It is also possible to remove a page label by omitting the
aLabel
parameter, as shown in
the code below (which assumes the existence of the labels in the previous example:
// The labels for pages 3-7 will be removed:
this.setPageLabels(3);
Creating Buttons
Though buttons are normally considered form fields, you can add them to any document. A
button may be used for a variety of purposes, such as opening files, playing sound or movie
clips, or submitting data to a web server. As you learned earlier, you can place text and
images on a button, making it a user-friendly interactive portion of your document. To
show or hide portions of graphic buttons, use the
Mouse Enter
and
Mouse Exit
events
or other types of control mechanisms to manage the usage of the button field’s
buttonSetIcon
method.
For example, the following code shows one icon when the mouse enters the button field,
and a different icon when the mouse exits:
var script = "var f = this.getField('myButton');";
script += "f.buttonSetIcon(this.getIcon('oneIcon');";
myButton.setAction("MouseEnter",script);
script = "var f = this.getField('myButton');";
script += "f.buttonSetIcon(this.getIcon('otherIcon');";
myButton.setAction("MouseExit",script);
186
Acrobat JavaScript Scripting Guide