6
Using Acrobat JavaScript in Forms
Forms Essentials
Button Properties
We will begin by creating a button named
myButton
:
var f = this.addField("myButton", "button", 0, [200, 250, 250, 400]);
To create a blue border along the edges of its surrounding rectangle, we will set its
strokeColor
property:
f.strokeColor = color.blue;
In addition, you may select from one of the following choices to specify its border style:
solid
(
border.s
),
beveled
(
border.b
),
dashed
(
border.d
),
inset
(
border.i
),
or
underline
(
border.u
).
In this case we will make the border appear beveled by setting its
borderStyle
property:
f.borderStyle = border.b;
To set the line thickness (in points) of the border, set its
lineWidth
property:
f.lineWidth = 1;
To set its background color to yellow, we will set its
fillColor
property:
f.fillColor = color.yellow;
To specify the text that appears on the button, invoke its
buttonSetCaption
method:
f.buttonSetCaption("Click Here");
You may set the text size, color, and font:
f.textSize = 16;
f.textColor = color.red;
f.textFont = font.Times;
To create a tooltip that appears when the mouse hovers over the button, set its
userName
property:
f.userName = "This is a button tooltip for myButton.";
In addition to the text, it is also possible to specify the relative positioning of the icon and
text on the button’s face. In this case, we will set the layout so that the icon appears to the
left of the text:
f.buttonPosition = position.iconTextH;
To specify whether the button should be visible either on screen or when printing, set its
display
property:
f.display = display.visible;
To set the button’s appearance in response to user interaction, set its
highlight
property to one of the following values:
none
(
highlight.n
)
,
invert
(
highlight.i
)
,
push
(
highlight.p
)
, or
outline
(
highlight.o
)
. In this example , we will specify that
the button appears to be pushed:
f.highlight = highlight.p;
94
Acrobat JavaScript Scripting Guide