Modifying the User Interface
Adding Navigation to PDF Documents
10
Defining the Appearance of a Link
The previous example contained code that set the appearance of the bounding rectangle
for the links through their
borderColor
and
borderWidth
properties. You may also
specify how the link will appear when it is clicked by setting its
highlightMode
property
to one of four values:
None
,
Outline
,
Invert
(the default), or
Push
.
For example, the following code sets the border color to blue, the border thickness to 2,
and the highlight mode to
Outline
for
myLink
:
myLink.borderColor = color.blue;
myLink.borderWidth = 2;
myLink.highlightMode = "Outline";
Editing Links
In addition to adding links and modifying their appearance, you may also remove links
from a document. To remove a known link object from a given page, retrieve its bounding
rectangle coordinates and invoke the
doc
object’s
removeLinks
method. In the
following example,
myLink
is removed from page 2 of the document:
var linkRect = myLink.rect;
this.removeLinks(2, linkRect);
To remove all links from the document, simply use the crop box for each page, as shown in
the code below:
for (var page = 0; page < this.numPages; page++)
{
var box = this.getPageBox("Crop", page);
this.removeLinks(page, box);
}
Creating Links from URLs
To open a web page for a given link, invoke the
link
object’s
setAction
method, and
pass in a script containing a call to the
doc
object’s
getURL
method.
For example, suppose you have created a
link
object named
myLink
. The following
code opens
http://myWebPage.com:
myLink.setAction("this.getURL('http://myWebPage.com')");
Linking to File Attachments
To open a file attachment, embed a JavaScript in the call to the
link
object’s
setAction
method. The script contains a call to the
app
object’s
openDoc
method.
The following example opens
myDoc.pdf
when
myLink
is clicked:
myLink.setAction("app.openDoc('/C/myDoc.pdf');");
Acrobat JavaScript Scripting Guide
177