Pdf - PdfJavaScriptAction
18 Nov 20262 minutes to read
Represents an action that executes JavaScript in a PDF document.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
let page: PdfPage = document.addPage();
// Create a JavaScript action
let action: PdfJavaScriptAction = new PdfJavaScriptAction('app.alert("Button clicked");');
// Create a button and assign the action
let field: PdfButtonField = new PdfButtonField(
page, 'JavaScript', { x: 20, y: 20, width: 120, height: 30 }
);
field.text = 'Execute script';
field.actions.mouseUp = action;
document.form.add(field);
// Save and destroy the document
document.save('output.pdf');
document.destroy();Properties
Get next PdfAction
Get the next action to be performed after the action represented by this instance.
Set next void
Set the next action to be performed after the action represented by this instance.
| Parameter | Type | Description |
|---|---|---|
| value | PdfAction |
The next action to be executed. |
Get script string
Gets the JavaScript code executed by the action.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the button field
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the JavaScript action
let action: PdfJavaScriptAction = field.actions.mouseUp as PdfJavaScriptAction;
// Get the JavaScript code
let script: string = action.script;
// Save and destroy the document
document.save('output.pdf');
document.destroy();Set script void
Sets the JavaScript code executed by the action.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the button field
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the JavaScript action
let action: PdfJavaScriptAction = field.actions.mouseUp as PdfJavaScriptAction;
// Set the JavaScript code
action.script = 'app.alert("Updated script");';
// Save and destroy the document
document.save('output.pdf');
document.destroy();| Parameter | Type | Description |
|---|---|---|
| value | string |
The JavaScript code to execute. |