Using Acrobat JavaScript in Forms
Forms Essentials
6
It is possible to specify the scaling characteristics of the icon within the button face. You
may determine when scaling takes place by setting the button’s
buttonScaleWhen
property to one of the following values:
always
(
scaleWhen.always
),
never
(
scaleWhen.never
), if the icon is
too big
(
scaleWhen.tooBig
), or if the icon is
too
small
(
scaleWhen.tooSmall
). In this case, we will specify that the button always scales:
f.buttonScaleWhen = scaleWhen.always;
You may also determine whether the scaling will be proportional by setting the
buttonScaleHow
property to one of the following values:
buttonScaleHow.proportional
or
buttonScaleHow.anamorphic
. In this case,
we will specify that the button scales proportionally:
f.buttonScaleHow = buttonScaleHow.proportional;
To guarantee that the icon scales within the bounds of the rectangular region for the
button, set the
buttonFitBounds
property:
f.buttonFitBounds = true;
You can specify the alignment characteristics of the icon by setting its
buttonAlignX
and
buttonAlignY
properties. This is done by specifying the percentage of the unused
horizontal space from the left or the vertical space from the bottom that is distributed. A
value of
50
would mean that the 50 percent of the unused space would be distributed to
the left or bottom of the icon (centered). We will center our icon in both dimensions:
f.buttonAlignX = 50;
f.buttonAlignY = 50;
Now that you have prepared the space within the button for the icon, you can import an
icon into the document and place it within the button’s area. To import an icon, invoke the
doc
object’s
importIcon
method. To place the icon in the button, invoke the button
object’s
setIcon
method. Assuming you have already made the icon available in the
document and that its variable name is
myIcon
, the following code would cause the icon
to appear on the button’s face:
f.setIcon(myIcon);
To rotate the button counterclockwise, set its
rotation
property:
f.rotation = 90;
Finally, you will undoubtedly wish to associate an action to be executed when the button is
clicked. You may do this by invoking the button’s
setAction
method, which requires a
trigger (an indication of the type of mouse event) and an associated script. The possible
triggers are
MouseUp
,
MouseDown
,
MouseEnter
,
MouseExit
,
OnFocus
, and
OnBlur
.
The following code displays a greeting when the button is clicked:
f.setAction("MouseUp", "app.alert(‘Hello’);" );
Acrobat JavaScript Scripting Guide
95