CreateJavascriptAction
IPDFDocument3 :: Actions

See Also Example
Collapse All

Creates a JavaScript action in a PDF document.

Syntax

LONG CreateJavascriptAction (
BSTR scriptContents
)
Parameters
scriptContents
String containing JavaScript code

Return value
Index of the created action.

Remarks

CreateJavascriptAction creates a JavaScript action. The script is compiled and executed by the JavaScript interpreter. Depending on the script, it can interact with the resulting document, such as updating form fields or changing the appearance of the document. Check Adobe Technical Note #5186, "Acrobat Forms JavaScript Object Specification" for the JavaScript script subclass language details.

The return value is an action identifier in the document's actions collection and can be used in AddControlToAction, OpenDocumentAction, PDFANNOTATION_OnBeforeFormatting, PDFANNOTATION_OnChange, PDFANNOTATION_OnKeyPress, PDFANNOTATION_OnSetFocus, PDFANNOTATION_OnLostFocus, PDFANNOTATION_OnMouseDown, PDFANNOTATION_OnMouseUp, PDFANNOTATION_OnMouseEnter, PDFANNOTATION_OnMouseExit, PDFANNOTATION_OnOtherControlChanged, PDFPAGE_SetAction, PDFANNOTATION_Action, PDFOUTLINENODE_Action.

Equivalent in new interface: IPDFDocument4::CreateJavascriptAction.

Example

How to Create a JavaSript Action (an Alert Window) and Associate It with a Button

Delphi
[copy to clipboard]
{ PDF object is supposed to be created }
PDF.PDFPAGE_CreateControl_Button('Btn1', 20, 90, 65, 105);
PDF.PDFANNOTATION_Caption := 'Alert demo';
actionIndex = PDF.CreateJavascriptAction('app.alert("This window was created as the result of CreateJavascriptAction")');
PDF.PDFANNOTATION_OnMouseUp := actionIndex;
C/C++
[copy to clipboard]
// PDF object is supposed to be created
PDF->PDFPAGE_CreateControl_Button("Btn1", 20, 90, 65, 105);
PDF->PDFANNOTATION_Caption = "Alert demo";
LONG actionIndex = PDF->CreateJavascriptAction("app.alert(\"This window was created as the result of CreateJavascriptAction\")");
PDF->PDFANNOTATION_OnMouseUp = actionIndex;
C#
[copy to clipboard]
// PDF object is supposed to be created
PDF.PDFPAGE_CreateControl_Button("Btn1", 20, 90, 65, 105);
PDF.PDFANNOTATION_Caption = "Alert demo";
long actionIndex = PDF.CreateJavascriptAction("app.alert(\"This window was created as the result of CreateJavascriptAction\")");
PDF.PDFANNOTATION_OnMouseUp = actionIndex;
Visual Basic
[copy to clipboard]
' PDF object is supposed to be created
PDF.PDFPAGE_CreateControl_Button "Btn1", 20, 90, 65, 105
PDF.PDFANNOTATION_Caption = "Alert demo"
actionIndex = PDF.CreateJavascriptAction("app.alert('This window was created as the result of CreateJavascriptAction')")
PDF.PDFANNOTATION_OnMouseUp = actionIndex

See Also

Reference