How do I associate additional actions (trigger events) with widgets and other annotations?

Q: My second question is about attaching an Action (a JavaScript) to
the MouseUp or
similar even in an interactive field. When describing how to associate
an action with
a link, the documentation simply says:

pdftron::PDF::Annot::SetLinkAction
Note:

This method is applicable only if this is e_Link annotation
However, I cannot find how to add actions to items such as e_Text,
e_Square, etc.

In reality, and for the time being I need to add the action to
annotations of type
e_Widget (all of them: e_button, e_check, e_text, e_radio, etc.).

How can I accomplish the same with PDFnet.
----

A: You can attach MouseUp, MouseDown and similar JavaScript actions
using so-called trigger events (see section 8.5.2 Trigger Events in
PDF Reference Manual).

An annotation, page object, or interactive form field may include an
entry named "AA" that specifies an additional-actions dictionary that
extends the set of events that can trigger the execution of an action.

TABLE 8.44 Entries in an annotation’s additional-actions dictionary:
------------

KEY | VALUE
E | An action to be performed when the cursor enters the
annotation’s active area.
X | An action to be performed when the cursor exits the
annotation’s active area.
D | An action to be performed when the mouse button is pressed
inside the annotation’s active area.
U | An action to be performed when the mouse button is released
inside the annotation’s active area.
Fo | (widget annotations only) An action to be performed when the
annotation receives the input focus.
Bl | (widget annotations only) (Uppercase B, lowercase L) An action
to be performed when the annotation loses the input focus. (The name
Bl stands for “blurred.”)
PO | An action to be performed when the page containing the
annotation is opened (for example, when the user navigates to it from
the next or previous page or by means of a link annotation or outline
item). The action is executed after the O action in the page’s
additional-actions dictionary (see Table 8.45) and the OpenAction
entry in the document catalog (see Table 3.25), if such actions are
present.
PC | An action to be performed when the page containing the
annotation is closed (for example, when the user navigates to the next
or previous page, or follows a link annotation or outline item). The
action is executed before the C action in the page’s additional-
actions dictionary (see Table 8.45), if present.
PV | An action to be performed when the page containing the
annotation becomes visible in the viewer application’s user interface.
PI |An action to be performed when the page containing the annotation
is no longer visible in the viewer application’s user interface.

The following is an example of how to set-up a trigger event for a
widget annotation:

Obj aa_dict = mywidget.GetSDFObj().PutDict("AA);

Obj alert_js = doc.CreateIndirectDict();
alert_js.PutName("S", "JavaScript");
alert_js.PutString("JS", "app.alert(' Hello World! ');");

// Associate this JS action with 'On Mouse Up' event.
aa_dict.Put("U", alert_js);
...

1 Like