Reference Guide
GdPicture14 Namespace / GdPicturePDF Class / SetAnnotationAction Method
The 0-based index of the required annotation within the current page. It must be a value from 0 to GetAnnotationCount-1.
A unique action identifier specifying a required action object. You can obtain this identifier when creating an action, for example, using the NewActionGoTo, NewActionGoToR, NewActionLaunch, NewActionJavaScript, NewActionNamed or NewActionURI methods.
Example





In This Topic
    SetAnnotationAction Method (GdPicturePDF)
    In This Topic
    Associates a specified action (identified with a unique action identifier) with a required annotation object, that is specified by its index related to the currently selected page of the loaded PDF document.

    At this time it is supported by the toolkit to only associate one action within one annotation object.

    Syntax
    'Declaration
     
    
    Public Function SetAnnotationAction( _
       ByVal AnnotationIdx As Integer, _
       ByVal ActionID As Integer _
    ) As GdPictureStatus
    public GdPictureStatus SetAnnotationAction( 
       int AnnotationIdx,
       int ActionID
    )
    public function SetAnnotationAction( 
        AnnotationIdx: Integer;
        ActionID: Integer
    ): GdPictureStatus; 
    public function SetAnnotationAction( 
       AnnotationIdx : int,
       ActionID : int
    ) : GdPictureStatus;
    public: GdPictureStatus SetAnnotationAction( 
       int AnnotationIdx,
       int ActionID
    ) 
    public:
    GdPictureStatus SetAnnotationAction( 
       int AnnotationIdx,
       int ActionID
    ) 

    Parameters

    AnnotationIdx
    The 0-based index of the required annotation within the current page. It must be a value from 0 to GetAnnotationCount-1.
    ActionID
    A unique action identifier specifying a required action object. You can obtain this identifier when creating an action, for example, using the NewActionGoTo, NewActionGoToR, NewActionLaunch, NewActionJavaScript, NewActionNamed or NewActionURI methods.

    Return Value

    A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.

    We strongly recommend always checking this status first.

    Remarks
    This method is only allowed for use with non-encrypted documents.

    Likewise always ensure that you have selected the correct page using the SelectPage method before applying an annotation index.

    Also be aware that at this time it is not supported by the toolkit to add multiple actions per one annotation object.

    Example
    How to create a PDF document of 5 pages with 4 link annotations on each page, while these links are associated with the predefined named actions.
    Dim failure As Boolean = True
    Dim oGdPicturePDF As New GdPicturePDF()
    If oGdPicturePDF.NewPDF() = GdPictureStatus.OK Then
        oGdPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
        oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
        Dim fontResName As String = oGdPicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica)
        Dim status As GdPictureStatus = oGdPicturePDF.GetStat()
        If status = GdPictureStatus.OK Then
            Dim actionFirstPageID As Integer = oGdPicturePDF.NewActionNamed(PdfActionNamed.ActionNamedFirstPage)
            status = oGdPicturePDF.GetStat()
            Dim actionPrevPageID As Integer = -1
            If status = GdPictureStatus.OK Then
                actionPrevPageID = oGdPicturePDF.NewActionNamed(PdfActionNamed.ActionNamedPrevPage)
                status = oGdPicturePDF.GetStat()
            End If
            Dim actionNextPageID As Integer = -1
            If status = GdPictureStatus.OK Then
                actionNextPageID = oGdPicturePDF.NewActionNamed(PdfActionNamed.ActionNamedNextPage)
                status = oGdPicturePDF.GetStat()
            End If
            Dim actionLastPageID As Integer = -1
            If status = GdPictureStatus.OK Then
                actionLastPageID = oGdPicturePDF.NewActionNamed(PdfActionNamed.ActionNamedLastPage)
                status = oGdPicturePDF.GetStat()
            End If
            If status = GdPictureStatus.OK Then
                Dim i As Integer = 0, annotID As Integer = -1
                Do
                    i += 1
                    failure = True
                    If (oGdPicturePDF.NewPage(21, 29.7F) = GdPictureStatus.OK) AndAlso
                       (oGdPicturePDF.SetFillColor(255, 0, 0) = GdPictureStatus.OK) AndAlso
                       (oGdPicturePDF.SetTextSize(12) = GdPictureStatus.OK) AndAlso
                       (oGdPicturePDF.DrawText(fontResName, 1, 0.5F, "This is the page " + i.ToString()) = GdPictureStatus.OK) AndAlso
                       (oGdPicturePDF.DrawTextBox(fontResName, 1, 1, 4, 2, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "First page") = GdPictureStatus.OK) AndAlso
                       (oGdPicturePDF.DrawTextBox(fontResName, 4, 1, 7, 2, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Prev. page") = GdPictureStatus.OK) AndAlso
                       (oGdPicturePDF.DrawTextBox(fontResName, 7, 1, 10, 2, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Next page") = GdPictureStatus.OK) AndAlso
                       (oGdPicturePDF.DrawTextBox(fontResName, 10, 1, 13, 2, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Last page") = GdPictureStatus.OK) Then
                        annotID = oGdPicturePDF.AddLinkAnnotation(1, 1, 3, 1, True, 255, 0, 0)
                        status = oGdPicturePDF.GetStat()
                        If (status = GdPictureStatus.OK) AndAlso (oGdPicturePDF.SetAnnotationAction(annotID, actionFirstPageID) = GdPictureStatus.OK) Then
                            annotID = oGdPicturePDF.AddLinkAnnotation(4, 1, 3, 1, True, 255, 0, 0)
                            status = oGdPicturePDF.GetStat()
                            If (status = GdPictureStatus.OK) AndAlso (oGdPicturePDF.SetAnnotationAction(annotID, actionPrevPageID) = GdPictureStatus.OK) Then
                                annotID = oGdPicturePDF.AddLinkAnnotation(7, 1, 3, 1, True, 255, 0, 0)
                                status = oGdPicturePDF.GetStat()
                                If (status = GdPictureStatus.OK) AndAlso (oGdPicturePDF.SetAnnotationAction(annotID, actionNextPageID) = GdPictureStatus.OK) Then
                                    annotID = oGdPicturePDF.AddLinkAnnotation(10, 1, 3, 1, True, 255, 0, 0)
                                    status = oGdPicturePDF.GetStat()
                                    If status = GdPictureStatus.OK Then
                                        status = oGdPicturePDF.SetAnnotationAction(annotID, actionLastPageID)
                                        failure = (status <> GdPictureStatus.OK)
                                    End If
                                End If
                            End If
                        End If
                    End If
                Loop While (Not failure) AndAlso (i < 5)
                If Not failure Then
                    failure = (oGdPicturePDF.SaveToFile("annots_with_actions.pdf") <> GdPictureStatus.OK)
                End If
            End If
        End If
    End If
    If failure Then
        MessageBox.Show("The example HAS NOT been followed successfully. The presumed status: " + oGdPicturePDF.GetStat().ToString(), "Example: SetAnnotationAction")
    Else
        MessageBox.Show("The example HAS been followed successfully." + vbCrLf + "The PDF document has been saved.", "Example: SetAnnotationAction")
    End If
    oGdPicturePDF.Dispose()
    bool failure = true;
    GdPicturePDF oGdPicturePDF = new GdPicturePDF();
    if (oGdPicturePDF.NewPDF() == GdPictureStatus.OK)
    {
        oGdPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
        oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
        string fontResName = oGdPicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica);
        GdPictureStatus status = oGdPicturePDF.GetStat();
        if (status == GdPictureStatus.OK)
        {
            int actionFirstPageID = oGdPicturePDF.NewActionNamed(PdfActionNamed.ActionNamedFirstPage);
            status = oGdPicturePDF.GetStat();
            int actionPrevPageID = -1;
            if (status == GdPictureStatus.OK)
            {
                actionPrevPageID = oGdPicturePDF.NewActionNamed(PdfActionNamed.ActionNamedPrevPage);
                status = oGdPicturePDF.GetStat();
            }
            int actionNextPageID = -1;
            if (status == GdPictureStatus.OK)
            {
                actionNextPageID = oGdPicturePDF.NewActionNamed(PdfActionNamed.ActionNamedNextPage);
                status = oGdPicturePDF.GetStat();
            }
            int actionLastPageID = -1;
            if (status == GdPictureStatus.OK)
            {
                actionLastPageID = oGdPicturePDF.NewActionNamed(PdfActionNamed.ActionNamedLastPage);
                status = oGdPicturePDF.GetStat();
            }
            if (status == GdPictureStatus.OK)
            {
                int i = 0, annotID = -1;
                do
                {
                    i++; failure = true;
                    if ((oGdPicturePDF.NewPage(21, 29.7f) == GdPictureStatus.OK) &&
                        (oGdPicturePDF.SetFillColor(255, 0, 0) == GdPictureStatus.OK) &&
                        (oGdPicturePDF.SetTextSize(12) == GdPictureStatus.OK) &&
                        (oGdPicturePDF.DrawText(fontResName, 1, 0.5f, "This is the page " + i.ToString()) == GdPictureStatus.OK) &&
                        (oGdPicturePDF.DrawTextBox(fontResName, 1, 1, 4, 2, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "First page") == GdPictureStatus.OK) &&
                        (oGdPicturePDF.DrawTextBox(fontResName, 4, 1, 7, 2, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Prev. page") == GdPictureStatus.OK) &&
                        (oGdPicturePDF.DrawTextBox(fontResName, 7, 1, 10, 2, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Next page") == GdPictureStatus.OK) &&
                        (oGdPicturePDF.DrawTextBox(fontResName, 10, 1, 13, 2, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Last page") == GdPictureStatus.OK))
                    {
                        annotID = oGdPicturePDF.AddLinkAnnotation(1, 1, 3, 1, true, 255, 0, 0);
                        status = oGdPicturePDF.GetStat();
                        if ((status == GdPictureStatus.OK) && (oGdPicturePDF.SetAnnotationAction(annotID, actionFirstPageID) == GdPictureStatus.OK))
                        {
                            annotID = oGdPicturePDF.AddLinkAnnotation(4, 1, 3, 1, true, 255, 0, 0);
                            status = oGdPicturePDF.GetStat();
                            if ((status == GdPictureStatus.OK) && (oGdPicturePDF.SetAnnotationAction(annotID, actionPrevPageID) == GdPictureStatus.OK))
                            {
                                annotID = oGdPicturePDF.AddLinkAnnotation(7, 1, 3, 1, true, 255, 0, 0);
                                status = oGdPicturePDF.GetStat();
                                if ((status == GdPictureStatus.OK) && (oGdPicturePDF.SetAnnotationAction(annotID, actionNextPageID) == GdPictureStatus.OK))
                                {
                                    annotID = oGdPicturePDF.AddLinkAnnotation(10, 1, 3, 1, true, 255, 0, 0);
                                    status = oGdPicturePDF.GetStat();
                                    if (status == GdPictureStatus.OK)
                                    {
                                        status = oGdPicturePDF.SetAnnotationAction(annotID, actionLastPageID);
                                        failure = (status != GdPictureStatus.OK);
                                    }
                                }
                            }
                        }
                    }
                } while ((!failure) && (i < 5));
                if (!failure)
                    failure = (oGdPicturePDF.SaveToFile("annots_with_actions.pdf") != GdPictureStatus.OK);
            }
        }
    }
    if (failure)
        MessageBox.Show("The example HAS NOT been followed successfully. The presumed status: " + oGdPicturePDF.GetStat().ToString(), "Example: SetAnnotationAction");
    else
        MessageBox.Show("The example HAS been followed successfully.\nThe PDF document has been saved.", "Example: SetAnnotationAction");
    oGdPicturePDF.Dispose();
    See Also