Modifying the User Interface
Adding Navigation to PDF Documents
10
Thumbnails
Creating Page Thumbnails
The
doc
object provides methods for adding and removing thumbnails in a document. To
add a set of thumbnails, invoke the
dialog
object’s
addThumbnails
method, which
creates thumbnails for a specified set of pages in the document. It accepts two optional
parameters:
nStart
and
nEnd
represent the beginning and end of an inclusive range of
page numbers.
For example, to add thumbnails for pages 2 through 5, use the following command:
this.addThumbnails({nStart: 2, nEnd: 5});
To add a thumbnail for just one page, just provide a value for
nStart
. The following
example adds a thumbnail for page 7:
this.addThumbnails({nStart: 7});
To add thumbnails from page 0 to a specified page, just provide a value for
nEnd
. The
following example adds thumbnails for pages 0-7:
this.addThumbnails({nEnd: 7});
To add thumbnails for all the pages in the document, omit both parameters:
this.addThumbnails();
To remove a set of thumbnails, invoke the
doc
object’s
removeThumbnails
method,
which accepts the same parameters as the
addThumbnails
method. For example, to
remove pages 2 to 5, use the following code:
this.removeThumbnails({nStart: 2, nEnd: 5});
Adding Page Actions with Page Thumbnails
You may associate a
Page Open
event with a page thumbnail. The most straightforward
way of doing this is to specify a
Page Open
action in the
Page Properties
dialog.
To customize a page action with Acrobat JavaScript, invoke the
doc
object’s
setPageAction
method for the page to be opened. In the following example, a greeting
is displayed when the user clicks on the thumbnail for page 2:
this.setPageAction(2, "Open", "app.alert(‘Hello’);");
The advantage of this approach is that you can dynamically build JavaScript strings to be
used in the method call.
Bookmarks
You can use Acrobat JavaScript to customize the appearance and behavior of the
bookmarks that appear in the
Bookmarks
navigation panel. Every PDF document has an
object known as
bookmarkRoot
, which is the root of the bookmark tree for the
document. It is possible to recursively add and modify levels of bookmarks underneath the
root. Each node is a
bookmark
object which can have any number of children.
Acrobat JavaScript Scripting Guide
171