Class PdfJavaScriptAction
Represents an JavaScript action in PDF document.
Inherited Members
Namespace: Syncfusion.Pdf.Interactive
Assembly: Syncfusion.Pdf.Portable.dll
Syntax
public class PdfJavaScriptAction : PdfAction, IPdfWrapper
Remarks
This PdfJavaScriptAction class is used to perform the JavaScript action in PDF document. Please refer the UG docuemntation link https://help.syncfusion.com/file-formats/pdf/working-with-action#javascript-action for more details.
Examples
//Create a new document
PdfDocument document = new PdfDocument();
//Add a page.
PdfPage page = document.Pages.Add();
//Create JavaScript action
PdfJavaScriptAction javaScriptAction = new PdfJavaScriptAction("app.alert(\"Hello World!!!\")");
//Add the JavaScript action
document.Actions.AfterOpen = javaScriptAction;
//Save and close the PDF document
document.Save("Output.pdf");
document.Close(true);
'Create a new document
Dim document As New PdfDocument()
'Add a page.
Dim page As PdfPage = document.Pages.Add()
'Create JavaScript action
Dim javaScriptAction As New PdfJavaScriptAction("app.alert(""Hello World!!!"")")
'Add the JavaScript action
document.Actions.AfterOpen = javaScriptAction
'Save and close the PDF document
document.Save("Output.pdf")
document.Close(True)
Constructors
PdfJavaScriptAction(String)
Initializes a new instance of the PdfJavaScriptAction class with JavaScript code
Declaration
public PdfJavaScriptAction(string javaScript)
Parameters
Type | Name | Description |
---|---|---|
System.String | javaScript | The JavaScript code. |
Examples
//Create a new document
PdfDocument document = new PdfDocument();
//Add a page.
PdfPage page = document.Pages.Add();
//Create JavaScript action
PdfJavaScriptAction javaScriptAction = new PdfJavaScriptAction("app.alert(\"Hello World!!!\")");
//Add the JavaScript action
document.Actions.AfterOpen = javaScriptAction;
//Save and close the PDF document
document.Save("Output.pdf");
document.Close(true);
'Create a new document
Dim document As New PdfDocument()
'Add a page.
Dim page As PdfPage = document.Pages.Add()
'Create JavaScript action
Dim javaScriptAction As New PdfJavaScriptAction("app.alert(""Hello World!!!"")")
'Add the JavaScript action
document.Actions.AfterOpen = javaScriptAction
'Save and close the PDF document
document.Save("Output.pdf")
document.Close(True)
Properties
JavaScript
Gets or sets the JavaScript code to be executed when this action is executed.
Declaration
public string JavaScript { get; set; }
Property Value
Type | Description |
---|---|
System.String | A string value representing valid JavaScript code to be executed. |
Examples
//Create a new document
PdfDocument document = new PdfDocument();
//Add a page.
PdfPage page = document.Pages.Add();
//Create JavaScript action
PdfJavaScriptAction javaScriptAction = new PdfJavaScriptAction("app.alert(\"Hello World!!!\")");
//Get the JavaScript code.
string javascriptcode = javaScriptAction.JavaScript;
//Add the JavaScript action
document.Actions.AfterOpen = javaScriptAction;
//Save and close the PDF document
document.Save("Output.pdf");
document.Close(true);
'Create a new document
Dim document As New PdfDocument()
'Add a page.
Dim page As PdfPage = document.Pages.Add()
'Create JavaScript action
Dim javaScriptAction As New PdfJavaScriptAction("app.alert(""Hello World!!!"")")
'Get the JavaScript code.
Dim javascriptcode As String = javaScriptAction.JavaScript
'Add the JavaScript action
document.Actions.AfterOpen = javaScriptAction
'Save and close the PDF document
document.Save("Output.pdf")
document.Close(True)
Name
Gets or sets the name. The name associated with the JavaScript block.
Declaration
public string Name { get; set; }
Property Value
Type |
---|
System.String |
Examples
// Create a new PDF document.
PdfDocument document = new PdfDocument();
// Get the JavaScript collection from the document.
PdfDocumentJavaScriptCollection javaScriptCollection = document.DocumentJavaScripts;
// Create a new JavaScript action that shows an alert with the message "Hello World!!!".
PdfJavaScriptAction javaScriptAction = new PdfJavaScriptAction("app.alert(\"Hello World!!!\")");
//Set name of the JavaScript action
javaScriptAction.Name = "Test";
// Add the JavaScript action to the collection.
javaScriptCollection.Add(javaScriptAction);
// Remove the JavaScript action from the collection.
javaScriptCollection.Remove(javaScriptAction);
// Insert the JavaScript action at the first position in the collection.
javaScriptCollection.Insert(0, javaScriptAction);
// Clear all JavaScript actions from the collection.
javaScriptCollection.Clear();
// Save the PDF document to a file named "Output.pdf".
document.Save("Output_Creation.pdf");
'Create a new PDF Document.
Dim document As PdfDocument = New PdfDocument
'Get the JavaScript collection from the document.
Dim javaScriptCollection As PdfDocumentJavaScriptCollection = document.DocumentJavaScripts
'Create a new JavaScript action that shows an alert with the message "Hello World!!!".
Dim javaScriptAction As PdfJavaScriptAction = New PdfJavaScriptAction("app.alert(""Hello World!!!"")")
'Set name of the JavaScript action
javaScriptAction.Name = "Test"
' Add the JavaScript action to the collection.
javaScriptCollection.Add(javaScriptAction)
' Remove the JavaScript action from the collection.
javaScriptCollection.Remove(javaScriptAction)
' Insert the JavaScript action at the first position in the collection.
javaScriptCollection.Insert(0, javaScriptAction)
' Clear all JavaScript actions from the collection.
javaScriptCollection.Clear
' Save the PDF document to a file named "Output.pdf".
document.Save("Output_Creation.pdf")
Methods
Initialize()
Initializes instance.
Declaration
protected override void Initialize()