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(PdfDestinationType,Int32,Single,Single,Single,Single,Single), NewActionGoToR(PdfDestinationType,String,Boolean,Int32,Single,Single,Single,Single,Single), NewActionLaunch, NewActionJavaScript, NewActionNamed or NewActionURI methods.
Example





In This Topic
GdPicture14 Namespace / GdPicturePDF Class / SetAnnotationAction Method

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(PdfDestinationType,Int32,Single,Single,Single,Single,Single), NewActionGoToR(PdfDestinationType,String,Boolean,Int32,Single,Single,Single,Single,Single), 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 gdpicturePDF As New GdPicturePDF()

If gdpicturePDF.NewPDF() = GdPictureStatus.OK Then

    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)

    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)

    Dim fontResName As String = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica)

    Dim status As GdPictureStatus = gdpicturePDF.GetStat()

    If status = GdPictureStatus.OK Then

        Dim actionFirstPageID As Integer = gdpicturePDF.NewActionNamed(PdfActionNamed.ActionNamedFirstPage)

        status = gdpicturePDF.GetStat()

        Dim actionPrevPageID As Integer = -1

        If status = GdPictureStatus.OK Then

            actionPrevPageID = gdpicturePDF.NewActionNamed(PdfActionNamed.ActionNamedPrevPage)

            status = gdpicturePDF.GetStat()

        End If

        Dim actionNextPageID As Integer = -1

        If status = GdPictureStatus.OK Then

            actionNextPageID = gdpicturePDF.NewActionNamed(PdfActionNamed.ActionNamedNextPage)

            status = gdpicturePDF.GetStat()

        End If

        Dim actionLastPageID As Integer = -1

        If status = GdPictureStatus.OK Then

            actionLastPageID = gdpicturePDF.NewActionNamed(PdfActionNamed.ActionNamedLastPage)

            status = gdpicturePDF.GetStat()

        End If

        If status = GdPictureStatus.OK Then

            Dim i As Integer = 0, annotID As Integer = -1

            Do

                i += 1

                failure = True

                If (gdpicturePDF.NewPage(21, 29.7F) = GdPictureStatus.OK) AndAlso

                   (gdpicturePDF.SetFillColor(255, 0, 0) = GdPictureStatus.OK) AndAlso

                   (gdpicturePDF.SetTextSize(12) = GdPictureStatus.OK) AndAlso

                   (gdpicturePDF.DrawText(fontResName, 1, 0.5F, "This is the page " + i.ToString()) = GdPictureStatus.OK) AndAlso

                   (gdpicturePDF.DrawTextBox(fontResName, 1, 1, 4, 2, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "First page") = GdPictureStatus.OK) AndAlso

                   (gdpicturePDF.DrawTextBox(fontResName, 4, 1, 7, 2, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Prev. page") = GdPictureStatus.OK) AndAlso

                   (gdpicturePDF.DrawTextBox(fontResName, 7, 1, 10, 2, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Next page") = GdPictureStatus.OK) AndAlso

                   (gdpicturePDF.DrawTextBox(fontResName, 10, 1, 13, 2, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Last page") = GdPictureStatus.OK) Then

                    annotID = gdpicturePDF.AddLinkAnnotation(1, 1, 3, 1, True, 255, 0, 0)

                    status = gdpicturePDF.GetStat()

                    If (status = GdPictureStatus.OK) AndAlso (gdpicturePDF.SetAnnotationAction(annotID, actionFirstPageID) = GdPictureStatus.OK) Then

                        annotID = gdpicturePDF.AddLinkAnnotation(4, 1, 3, 1, True, 255, 0, 0)

                        status = gdpicturePDF.GetStat()

                        If (status = GdPictureStatus.OK) AndAlso (gdpicturePDF.SetAnnotationAction(annotID, actionPrevPageID) = GdPictureStatus.OK) Then

                            annotID = gdpicturePDF.AddLinkAnnotation(7, 1, 3, 1, True, 255, 0, 0)

                            status = gdpicturePDF.GetStat()

                            If (status = GdPictureStatus.OK) AndAlso (gdpicturePDF.SetAnnotationAction(annotID, actionNextPageID) = GdPictureStatus.OK) Then

                                annotID = gdpicturePDF.AddLinkAnnotation(10, 1, 3, 1, True, 255, 0, 0)

                                status = gdpicturePDF.GetStat()

                                If status = GdPictureStatus.OK Then

                                    status = gdpicturePDF.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 = (gdpicturePDF.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: " + gdpicturePDF.GetStat().ToString(), "Example: SetAnnotationAction")

Else

    MessageBox.Show("The example HAS been followed successfully." + vbCrLf + "The PDF document has been saved.", "Example: SetAnnotationAction")

End If

gdpicturePDF.Dispose()
bool failure = true;

GdPicturePDF gdpicturePDF = new GdPicturePDF();

if (gdpicturePDF.NewPDF() == GdPictureStatus.OK)

{

    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);

    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);

    string fontResName = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica);

    GdPictureStatus status = gdpicturePDF.GetStat();

    if (status == GdPictureStatus.OK)

    {

        int actionFirstPageID = gdpicturePDF.NewActionNamed(PdfActionNamed.ActionNamedFirstPage);

        status = gdpicturePDF.GetStat();

        int actionPrevPageID = -1;

        if (status == GdPictureStatus.OK)

        {

            actionPrevPageID = gdpicturePDF.NewActionNamed(PdfActionNamed.ActionNamedPrevPage);

            status = gdpicturePDF.GetStat();

        }

        int actionNextPageID = -1;

        if (status == GdPictureStatus.OK)

        {

            actionNextPageID = gdpicturePDF.NewActionNamed(PdfActionNamed.ActionNamedNextPage);

            status = gdpicturePDF.GetStat();

        }

        int actionLastPageID = -1;

        if (status == GdPictureStatus.OK)

        {

            actionLastPageID = gdpicturePDF.NewActionNamed(PdfActionNamed.ActionNamedLastPage);

            status = gdpicturePDF.GetStat();

        }

        if (status == GdPictureStatus.OK)

        {

            int i = 0, annotID = -1;

            do

            {

                i++; failure = true;

                if ((gdpicturePDF.NewPage(21, 29.7f) == GdPictureStatus.OK) &&

                    (gdpicturePDF.SetFillColor(255, 0, 0) == GdPictureStatus.OK) &&

                    (gdpicturePDF.SetTextSize(12) == GdPictureStatus.OK) &&

                    (gdpicturePDF.DrawText(fontResName, 1, 0.5f, "This is the page " + i.ToString()) == GdPictureStatus.OK) &&

                    (gdpicturePDF.DrawTextBox(fontResName, 1, 1, 4, 2, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "First page") == GdPictureStatus.OK) &&

                    (gdpicturePDF.DrawTextBox(fontResName, 4, 1, 7, 2, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Prev. page") == GdPictureStatus.OK) &&

                    (gdpicturePDF.DrawTextBox(fontResName, 7, 1, 10, 2, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Next page") == GdPictureStatus.OK) &&

                    (gdpicturePDF.DrawTextBox(fontResName, 10, 1, 13, 2, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Last page") == GdPictureStatus.OK))

                {

                    annotID = gdpicturePDF.AddLinkAnnotation(1, 1, 3, 1, true, 255, 0, 0);

                    status = gdpicturePDF.GetStat();

                    if ((status == GdPictureStatus.OK) && (gdpicturePDF.SetAnnotationAction(annotID, actionFirstPageID) == GdPictureStatus.OK))

                    {

                        annotID = gdpicturePDF.AddLinkAnnotation(4, 1, 3, 1, true, 255, 0, 0);

                        status = gdpicturePDF.GetStat();

                        if ((status == GdPictureStatus.OK) && (gdpicturePDF.SetAnnotationAction(annotID, actionPrevPageID) == GdPictureStatus.OK))

                        {

                            annotID = gdpicturePDF.AddLinkAnnotation(7, 1, 3, 1, true, 255, 0, 0);

                            status = gdpicturePDF.GetStat();

                            if ((status == GdPictureStatus.OK) && (gdpicturePDF.SetAnnotationAction(annotID, actionNextPageID) == GdPictureStatus.OK))

                            {

                                annotID = gdpicturePDF.AddLinkAnnotation(10, 1, 3, 1, true, 255, 0, 0);

                                status = gdpicturePDF.GetStat();

                                if (status == GdPictureStatus.OK)

                                {

                                    status = gdpicturePDF.SetAnnotationAction(annotID, actionLastPageID);

                                    failure = (status != GdPictureStatus.OK);

                                }

                            }

                        }

                    }

                }

            } while ((!failure) && (i < 5));

            if (!failure)

                failure = (gdpicturePDF.SaveToFile("annots_with_actions.pdf") != GdPictureStatus.OK);

        }

    }

}

if (failure)

    MessageBox.Show("The example HAS NOT been followed successfully. The presumed status: " + gdpicturePDF.GetStat().ToString(), "Example: SetAnnotationAction");

else

    MessageBox.Show("The example HAS been followed successfully.\nThe PDF document has been saved.", "Example: SetAnnotationAction");

gdpicturePDF.Dispose();
See Also