GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / GetActionJavaScript Method
A unique action identifier specifying a required action object. You can obtain this identifier using these methods: GetViewerOpenActionID, GetBookmarkActionID, GetFormFieldActionID, GetAnnotationActionID or NewActionJavaScript.

Please ensure that the type of the action object specified by this ActionID is exactly the PdfActionType.ActionTypeJavaScript. You can check the type of the required action object using the GetActionType method as it is shown in the example below.

Example





In This Topic
GetActionJavaScript Method (GdPicturePDF)
In This Topic
Returns the JavaScript script of the specified JavaScript action. A JavaScript action (introduced in PDF 1.3) causes a script to be compiled and executed by the JavaScript interpreter. JavaScript implements objects, methods, and properties that enable you to manipulate PDF files, modify the appearance of PDF files, etc. You can tie JavaScript code to a specific PDF document, a page or a field, and much more. You can read more about the content and effects of JavaScript scripts in the JavaScript for Acrobat API Reference.
Syntax
'Declaration
 
Public Function GetActionJavaScript( _
   ByVal ActionID As Integer _
) As String
public string GetActionJavaScript( 
   int ActionID
)
public function GetActionJavaScript( 
    ActionID: Integer
): String; 
public function GetActionJavaScript( 
   ActionID : int
) : String;
public: string* GetActionJavaScript( 
   int ActionID
) 
public:
String^ GetActionJavaScript( 
   int ActionID
) 

Parameters

ActionID
A unique action identifier specifying a required action object. You can obtain this identifier using these methods: GetViewerOpenActionID, GetBookmarkActionID, GetFormFieldActionID, GetAnnotationActionID or NewActionJavaScript.

Please ensure that the type of the action object specified by this ActionID is exactly the PdfActionType.ActionTypeJavaScript. You can check the type of the required action object using the GetActionType method as it is shown in the example below.

Return Value

A string containing the JavaScript script to be executed. The GetStat method can be subsequently used to determine if this method has been successful.
Remarks
This method is only allowed for use with non-encrypted documents.

It is recommend to use the GetStat method to identify the specific reason for the method's failure, if any. For example, if the action object specified by the action identifier is not of the type PdfActionType.ActionTypeJavaScript, the reason for the method's failure is GdPictureStatus.InvalidParameter.

Example
How to find out the used script of a JavaScript action associated with the form field in the PDF document.
Dim caption As String = "Example: GetActionJavaScript"
Dim gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.LoadFromFile("forms_actions.pdf", False) = GdPictureStatus.OK Then
    Dim FormsCount As Integer = gdpicturePDF.GetFormFieldsCount()
    Dim status As GdPictureStatus = gdpicturePDF.GetStat()
    If status <> GdPictureStatus.OK OrElse FormsCount = 0 Then
        MessageBox.Show("The GetFormFieldsCount() method has failed or " + vbCrLf + " this PDF document doesn't include any form fields.", caption)
    Else
        Dim ActionsJS As String = ""
        For x As Integer = 0 To FormsCount - 1
            Dim FFId As Integer = gdpicturePDF.GetFormFieldId(x)
            If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                Dim ActionId As Integer = gdpicturePDF.GetFormFieldActionID(FFId)
                If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                    Dim ActionType As PdfActionType = gdpicturePDF.GetActionType(ActionId)
                    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                        If ActionType = PdfActionType.ActionTypeJavaScript Then
                            Dim script As String = gdpicturePDF.GetActionJavaScript(ActionId)
                            status = gdpicturePDF.GetStat()
                            If status = GdPictureStatus.OK Then
                                ActionsJS = ActionsJS + "Form Field Nr." + (x + 1).ToString() + " has associated JavaScript action with this script:" + vbCrLf + script + vbCrLf
                            Else
                                ActionsJS = ActionsJS + "Form Field Nr." + (x + 1).ToString() + " has associated JavaScript action, but the GetActionJavaScript() method has failed with the status: " + status.ToString() + vbCrLf
                            End If
                        End If
                    End If
                End If
            End If
        Next
        MessageBox.Show(ActionsJS, caption)
    End If
Else
    MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: GetActionJavaScript";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("forms_actions.pdf", false) == GdPictureStatus.OK)
{
    int FormsCount = gdpicturePDF.GetFormFieldsCount();
    GdPictureStatus status = gdpicturePDF.GetStat();
    if (status != GdPictureStatus.OK || FormsCount == 0)
    {
        MessageBox.Show("The GetFormFieldsCount() method has failed or \n this PDF document doesn't include any form fields.", caption);
    }
    else
    {
        string ActionsJS = "";
        for (int x = 0; x <= FormsCount - 1; x++)
        {
            int FFId = gdpicturePDF.GetFormFieldId(x);
            if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
            {
                int ActionId = gdpicturePDF.GetFormFieldActionID(FFId);
                if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                {
                    PdfActionType ActionType = gdpicturePDF.GetActionType(ActionId);
                    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                    {
                        if (ActionType == PdfActionType.ActionTypeJavaScript)
                        {
                            string script = gdpicturePDF.GetActionJavaScript(ActionId);
                            status = gdpicturePDF.GetStat();
                            if (status == GdPictureStatus.OK)
                            {
                                ActionsJS = ActionsJS + "Form Field Nr." + (x + 1).ToString() + " has associated JavaScript action with this script:\n" + script + "\n";
                            }
                            else
                            {
                                ActionsJS = ActionsJS + "Form Field Nr." + (x + 1).ToString() + " has associated JavaScript action, but the GetActionJavaScript() method has failed with the status: " + status.ToString() + "\n";
                            }
                        }
                    }
                }
            }
        }
        MessageBox.Show(ActionsJS, caption);
    }
}
else
{
    MessageBox.Show("The file can't be loaded.", caption);
}
gdpicturePDF.Dispose();
See Also