Reference Guide
GdPicture14 Namespace / GdPicturePDF Class / AddLinkToPageAnnotation Method
The horizontal (X) coordinate of the closest point to the currently defined origin, where the annotation's bounding box is to be located. The value is expressed in the current units specified by the SetMeasurementUnit method and it is related to the current page. For further assistance, please see the Remarks section below.
The vertical (Y) coordinate of the closest point to the currently defined origin, where the annotation's bounding box is to be located. The value is expressed in the current units specified by the SetMeasurementUnit method and it is related to the current page. For further assistance, please see the Remarks section below.
The width of the annotation's bounding box, expressed in the current units specified by the SetMeasurementUnit method.
The height of the annotation's bounding box, expressed in the current units specified by the SetMeasurementUnit method.
The page number of the destination's page in the current document. It must be a value from 1 to GetPageCount.
The horizontal (X) coordinate of the closest point to the currently defined origin on the destination's page, where the link jumps. The value is expressed in the current units specified by the SetMeasurementUnit method and it is related to the current page. For further assistance, please see the Remarks section below.
The vertical (Y) coordinate of the closest point to the currently defined origin on the destination's page, where the link jumps. The value is expressed in the current units specified by the SetMeasurementUnit method and it is related to the current page. For further assistance, please see the Remarks section below.
Set this parameter to true, if you want to display borders around the annotation's bounding box, otherwise set it to false. These borders are inscribed within the annotation's bounding box and they are drawn with the required color.
The amount of red color to be used for the resulting color when displaying the link borders, if the Borders parameter is set to true. Use the value between 0 and 255.
The amount of green color to be used for the resulting color when displaying the link borders, if the Borders parameter is set to true. Use the value between 0 and 255.
The amount of blue color to be used for the resulting color when displaying the link borders, if the Borders parameter is set to true. Use the value between 0 and 255.
Example





In This Topic
    AddLinkToPageAnnotation Method (GdPicturePDF)
    In This Topic
    Adds a link annotation object on the currently selected page of the loaded PDF document. The subtype attribute of this annotation is "Link". This annotation represents a hypertext link annotation, that has associated a go-to-page action (the action of the type GoTo). The destination of the assigned action is the page in the current document according to your preference.

    This method uses the RGB color space for specifying the required color of the annotation object, here it is the color of the annotation's borders.

    For further assistance, please see the Actions section of the GdPicturePDF class in the Reference Guide.

    Syntax
    'Declaration
     
    
    Public Function AddLinkToPageAnnotation( _
       ByVal Left As Single, _
       ByVal Top As Single, _
       ByVal Width As Single, _
       ByVal Height As Single, _
       ByVal PageNum As Integer, _
       ByVal DstLeft As Single, _
       ByVal DstTop As Single, _
       ByVal Borders As Boolean, _
       ByVal Red As Byte, _
       ByVal Green As Byte, _
       ByVal Blue As Byte _
    ) As Integer
    public int AddLinkToPageAnnotation( 
       float Left,
       float Top,
       float Width,
       float Height,
       int PageNum,
       float DstLeft,
       float DstTop,
       bool Borders,
       byte Red,
       byte Green,
       byte Blue
    )
    public function AddLinkToPageAnnotation( 
        Left: Single;
        Top: Single;
        Width: Single;
        Height: Single;
        PageNum: Integer;
        DstLeft: Single;
        DstTop: Single;
        Borders: Boolean;
        Red: Byte;
        Green: Byte;
        Blue: Byte
    ): Integer; 
    public function AddLinkToPageAnnotation( 
       Left : float,
       Top : float,
       Width : float,
       Height : float,
       PageNum : int,
       DstLeft : float,
       DstTop : float,
       Borders : boolean,
       Red : byte,
       Green : byte,
       Blue : byte
    ) : int;
    public: int AddLinkToPageAnnotation( 
       float Left,
       float Top,
       float Width,
       float Height,
       int PageNum,
       float DstLeft,
       float DstTop,
       bool Borders,
       byte Red,
       byte Green,
       byte Blue
    ) 
    public:
    int AddLinkToPageAnnotation( 
       float Left,
       float Top,
       float Width,
       float Height,
       int PageNum,
       float DstLeft,
       float DstTop,
       bool Borders,
       byte Red,
       byte Green,
       byte Blue
    ) 

    Parameters

    Left
    The horizontal (X) coordinate of the closest point to the currently defined origin, where the annotation's bounding box is to be located. The value is expressed in the current units specified by the SetMeasurementUnit method and it is related to the current page. For further assistance, please see the Remarks section below.
    Top
    The vertical (Y) coordinate of the closest point to the currently defined origin, where the annotation's bounding box is to be located. The value is expressed in the current units specified by the SetMeasurementUnit method and it is related to the current page. For further assistance, please see the Remarks section below.
    Width
    The width of the annotation's bounding box, expressed in the current units specified by the SetMeasurementUnit method.
    Height
    The height of the annotation's bounding box, expressed in the current units specified by the SetMeasurementUnit method.
    PageNum
    The page number of the destination's page in the current document. It must be a value from 1 to GetPageCount.
    DstLeft
    The horizontal (X) coordinate of the closest point to the currently defined origin on the destination's page, where the link jumps. The value is expressed in the current units specified by the SetMeasurementUnit method and it is related to the current page. For further assistance, please see the Remarks section below.
    DstTop
    The vertical (Y) coordinate of the closest point to the currently defined origin on the destination's page, where the link jumps. The value is expressed in the current units specified by the SetMeasurementUnit method and it is related to the current page. For further assistance, please see the Remarks section below.
    Borders
    Set this parameter to true, if you want to display borders around the annotation's bounding box, otherwise set it to false. These borders are inscribed within the annotation's bounding box and they are drawn with the required color.
    Red
    The amount of red color to be used for the resulting color when displaying the link borders, if the Borders parameter is set to true. Use the value between 0 and 255.
    Green
    The amount of green color to be used for the resulting color when displaying the link borders, if the Borders parameter is set to true. Use the value between 0 and 255.
    Blue
    The amount of blue color to be used for the resulting color when displaying the link borders, if the Borders parameter is set to true. Use the value between 0 and 255.

    Return Value

    The unique annotation index from 0 to GetAnnotationCount-1 related to the currently selected page. 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.

    Please always ensure that you have selected the correct page using the SelectPage method before adding a required annotation.

    You also need to be aware that the values of coordinates and dimensions are expressed in the current units defined by the SetMeasurementUnit method according to the current coordinate space defined by the SetOrigin method.

    Example
    How to create a link annotation on a new page in the PDF document, that points to a page in the same document. This example creates two pages in a new PDF document with link annotation on each of them, so that these links point to the respective pages.
    Dim caption As String = "Example: AddLinkToPageAnnotation"
    Dim oGdPicturePDF As GdPicturePDF = New GdPicturePDF()
    If (oGdPicturePDF.NewPDF() = GdPictureStatus.OK) AndAlso
       (oGdPicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) AndAlso
       (oGdPicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) Then
        oGdPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
        oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
        oGdPicturePDF.SelectPage(1)
        Dim textSize As Single = 20
        Dim fontResName As String = oGdPicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica)
        If (oGdPicturePDF.GetStat() = GdPictureStatus.OK) AndAlso
           (oGdPicturePDF.SetFillColor(255, 140, 0) = GdPictureStatus.OK) AndAlso
           (oGdPicturePDF.SetTextSize(textSize) = GdPictureStatus.OK) Then
            Dim textW As Single = oGdPicturePDF.GetTextWidth(fontResName, textSize, "Goto Page 2")
            Dim status1 As GdPictureStatus = oGdPicturePDF.GetStat()
            Dim textH As Single = oGdPicturePDF.GetTextHeight(fontResName, textSize, False)
            Dim status2 As GdPictureStatus = oGdPicturePDF.GetStat()
            If (status1 = GdPictureStatus.OK) AndAlso (status2 = GdPictureStatus.OK) Then
                If oGdPicturePDF.DrawText(fontResName, 0, textH, "Goto page 2") = GdPictureStatus.OK Then
                    'The currently selected page is 1.
                    Dim annotID As Integer = oGdPicturePDF.AddLinkToPageAnnotation(0, 0, textW, textH, 2, 0, 0, True, 0, 0, 255)
                    'Each valid annotID should be >= 0, but it is recommended to check the error status, not the returned ID.
                    If oGdPicturePDF.GetStat() = GdPictureStatus.OK Then
                        'Please always select the required page before adding an annotation.
                        If (oGdPicturePDF.SelectPage(2) = GdPictureStatus.OK) AndAlso
                           (oGdPicturePDF.SetFillColor(255, 140, 0) = GdPictureStatus.OK) AndAlso
                           (oGdPicturePDF.SetTextSize(textSize) = GdPictureStatus.OK) AndAlso
                           (oGdPicturePDF.DrawText(fontResName, 0, textH, "Goto page 1") = GdPictureStatus.OK) Then
                            'The currently selected page is 2.
                            annotID = oGdPicturePDF.AddLinkToPageAnnotation(0, 0, textW, textH, 1, 0, 0, True, 0, 0, 255)
                            'Each valid annotID should be >= 0, but it is recommended to check the error status, not the returned ID.
                            If oGdPicturePDF.GetStat() = GdPictureStatus.OK Then
                                If oGdPicturePDF.SaveToFile("linkpageannot.pdf") = GdPictureStatus.OK Then
                                    MessageBox.Show("The example has been followed successfully and the file has been saved.", caption)
                                Else
                                    MessageBox.Show("The example has been followed successfully, but the file has NOT been saved. Status: " + oGdPicturePDF.GetStat(), caption)
                                End If
                            Else
                                MessageBox.Show("The AddLinkToPageAnnotation() method has failed with the status: " + oGdPicturePDF.GetStat().ToString(), caption)
                            End If
                        Else
                            MessageBox.Show("The DrawText() method has failed with the status: " + oGdPicturePDF.GetStat().ToString(), caption)
                        End If
                    Else
                        MessageBox.Show("The AddLinkToPageAnnotation() method has failed with the status: " + oGdPicturePDF.GetStat().ToString(), caption)
                    End If
                Else
                    MessageBox.Show("The DrawText() method has failed with the status: " + oGdPicturePDF.GetStat().ToString(), caption)
                End If
            Else
                MessageBox.Show("The GetTextWidth()/GetTextHeight() method has failed with the status: " + status1.ToString() + "/" + status2.ToString(), caption)
            End If
        Else
            MessageBox.Show("Adding font and its properties has failed with the status: " + oGdPicturePDF.GetStat().ToString(), caption)
        End If
    Else
        MessageBox.Show("The file can't be created.", caption)
    End If
    oGdPicturePDF.Dispose()
    string caption = "Example: AddLinkToPageAnnotation";
    GdPicturePDF oGdPicturePDF = new GdPicturePDF();
    if ((oGdPicturePDF.NewPDF() == GdPictureStatus.OK) &&
        (oGdPicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK) &&
        (oGdPicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK))
    {
        oGdPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
        oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
        oGdPicturePDF.SelectPage(1);
        float textSize = 20;
        string fontResName = oGdPicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica);
        if ((oGdPicturePDF.GetStat() == GdPictureStatus.OK) &&
            (oGdPicturePDF.SetFillColor(255, 140, 0) == GdPictureStatus.OK) &&
            (oGdPicturePDF.SetTextSize(textSize) == GdPictureStatus.OK))
        {
            float textW = oGdPicturePDF.GetTextWidth(fontResName, textSize, "Goto Page 2");
            GdPictureStatus status1 = oGdPicturePDF.GetStat();
            float textH = oGdPicturePDF.GetTextHeight(fontResName, textSize, false);
            GdPictureStatus status2 = oGdPicturePDF.GetStat();
            if ((status1 == GdPictureStatus.OK) && (status2 == GdPictureStatus.OK))
            {
                if (oGdPicturePDF.DrawText(fontResName, 0, textH, "Goto page 2") == GdPictureStatus.OK)
                {
                    //The currently selected page is 1.
                    int annotID = oGdPicturePDF.AddLinkToPageAnnotation(0, 0, textW, textH, 2, 0, 0, true, 0, 0, 255);
                    //Each valid annotID should be >= 0, but it is recommended to check the error status, not the returned ID.
                    if (oGdPicturePDF.GetStat() == GdPictureStatus.OK)
                    {
                        //Please always select the required page before adding an annotation.
                        if ((oGdPicturePDF.SelectPage(2) == GdPictureStatus.OK) &&
                            (oGdPicturePDF.SetFillColor(255, 140, 0) == GdPictureStatus.OK) &&
                            (oGdPicturePDF.SetTextSize(textSize) == GdPictureStatus.OK) &&
                            (oGdPicturePDF.DrawText(fontResName, 0, textH, "Goto page 1") == GdPictureStatus.OK))
                        {
                            //The currently selected page is 2.
                            annotID = oGdPicturePDF.AddLinkToPageAnnotation(0, 0, textW, textH, 1, 0, 0, true, 0, 0, 255);
                            //Each valid annotID should be >= 0, but it is recommended to check the error status, not the returned ID.
                            if (oGdPicturePDF.GetStat() == GdPictureStatus.OK)
                            {
                                if (oGdPicturePDF.SaveToFile("linkpageannot.pdf") == GdPictureStatus.OK)
                                    MessageBox.Show("The example has been followed successfully and the file has been saved.", caption);
                                else
                                    MessageBox.Show("The example has been followed successfully, but the file has NOT been saved. Status: " + oGdPicturePDF.GetStat(), caption);
                            }
                            else
                                MessageBox.Show("The AddLinkToPageAnnotation() method has failed with the status: " + oGdPicturePDF.GetStat().ToString(), caption);
                        }
                        else
                            MessageBox.Show("The DrawText() method has failed with the status: " + oGdPicturePDF.GetStat().ToString(), caption);
                    }
                    else
                        MessageBox.Show("The AddLinkToPageAnnotation() method has failed with the status: " + oGdPicturePDF.GetStat().ToString(), caption);
                }
                else
                    MessageBox.Show("The DrawText() method has failed with the status: " + oGdPicturePDF.GetStat().ToString(), caption);
            }
            else
                MessageBox.Show("The GetTextWidth()/GetTextHeight() method has failed with the status: " + status1.ToString() + "/" + status2.ToString(), caption);
        }
        else
            MessageBox.Show("Adding font and its properties has failed with the status: " + oGdPicturePDF.GetStat().ToString(), caption);
    }
    else
        MessageBox.Show("The file can't be created.", caption);
    oGdPicturePDF.Dispose();
    See Also