menu

Document Processing

PdfDocumentJavaScriptCollection Class - C# PDF Library API Reference | Syncfusion

    Show / Hide Table of Contents

    PdfDocumentJavaScriptCollection Class

    Represents a collection of JavaScript actions within a PDF document.

    Inheritance
    System.Object
    PdfCollection
    PdfDocumentJavaScriptCollection
    Implements
    System.Collections.IEnumerable
    Inherited Members
    PdfCollection.Count
    PdfCollection.GetEnumerator()
    PdfCollection.List
    Namespace: Syncfusion.Pdf
    Assembly: Syncfusion.Pdf.Base.dll
    Syntax
    public class PdfDocumentJavaScriptCollection : PdfCollection, IEnumerable
    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")

    Properties

    Item[Int32]

    Gets the JavaScript action at the specified index in the collection.

    Declaration
    public PdfJavaScriptAction this[int index] { get; }
    Parameters
    Type Name Description
    System.Int32 index

    The zero-based index of the JavaScript action to get.

    Property Value
    Type Description
    PdfJavaScriptAction

    The PdfJavaScriptAction at the specified index.

    Methods

    Add(PdfJavaScriptAction)

    Adds a JavaScript action to the collection.

    Declaration
    public void Add(PdfJavaScriptAction javaScriptAction)
    Parameters
    Type Name Description
    PdfJavaScriptAction javaScriptAction

    The JavaScript action to add.

    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);
    // 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)
    ' Save the PDF document to a file named "Output.pdf".
    document.Save("Output_Creation.pdf")

    Clear()

    Removes all JavaScript actions from the collection.

    Declaration
    public void Clear()
    Examples
    // Create a new PDF document.
    PdfDocument document = new PdfDocument();
    // Get the JavaScript collection from the document.
    PdfDocumentJavaScriptCollection javaScriptCollection = document.DocumentJavaScripts;
    // 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
    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")

    Remove(PdfJavaScriptAction)

    Removes the specified JavaScript action from the collection.

    Declaration
    public void Remove(PdfJavaScriptAction javaScriptAction)
    Parameters
    Type Name Description
    PdfJavaScriptAction javaScriptAction

    The JavaScript action to remove.

    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";
    // Remove the JavaScript action from the collection.
    javaScriptCollection.Remove(javaScriptAction);
    // 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"
    ' Remove the JavaScript action from the collection.
    javaScriptCollection.Remove(javaScriptAction)
    ' Save the PDF document to a file named "Output.pdf".
    document.Save("Output_Creation.pdf")

    RemoveAt(Int32)

    Removes the specified JavaScript action at the given index from the DocumentJavaScriptCollection.

    Declaration
    public void RemoveAt(int index)
    Parameters
    Type Name Description
    System.Int32 index

    The index.

    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";
    // Remove the JavaScript action from the collection.
    javaScriptCollection.RemoveAt(0);
    // 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"
    ' Remove the JavaScript action from the collection.
    javaScriptCollection.RemoveAt(0)
    ' Save the PDF document to a file named "Output.pdf".
    document.Save("Output_Creation.pdf")

    Implements

    System.Collections.IEnumerable
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved