Reference Guide
GdPicture14 Namespace / GdPicturePDF Class / AddLinkAnnotation Method / AddLinkAnnotation(Single,Single,Single,Single,Boolean,Byte,Byte,Byte) 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.
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
    AddLinkAnnotation(Single,Single,Single,Single,Boolean,Byte,Byte,Byte) Method
    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 an "action ready" link (hypertext link), in other words you can associate an action with this annotation object 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.

    You can subsequently assign an action to the created link using the SetAnnotationAction method, as it is explained in the example below. For further assistance, please see the Actions section of the GdPicturePDF class in the Reference Guide.
    Syntax
    'Declaration
     
    
    Public Overloads Function AddLinkAnnotation( _
       ByVal Left As Single, _
       ByVal Top As Single, _
       ByVal Width As Single, _
       ByVal Height As Single, _
       ByVal Borders As Boolean, _
       ByVal Red As Byte, _
       ByVal Green As Byte, _
       ByVal Blue As Byte _
    ) As Integer
    public int AddLinkAnnotation( 
       float Left,
       float Top,
       float Width,
       float Height,
       bool Borders,
       byte Red,
       byte Green,
       byte Blue
    )
    public function AddLinkAnnotation( 
        Left: Single;
        Top: Single;
        Width: Single;
        Height: Single;
        Borders: Boolean;
        Red: Byte;
        Green: Byte;
        Blue: Byte
    ): Integer; 
    public function AddLinkAnnotation( 
       Left : float,
       Top : float,
       Width : float,
       Height : float,
       Borders : boolean,
       Red : byte,
       Green : byte,
       Blue : byte
    ) : int;
    public: int AddLinkAnnotation( 
       float Left,
       float Top,
       float Width,
       float Height,
       bool Borders,
       byte Red,
       byte Green,
       byte Blue
    ) 
    public:
    int AddLinkAnnotation( 
       float Left,
       float Top,
       float Width,
       float Height,
       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.
    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. Please always use the GetStat method to determine if this method has been successful.
    Remarks
    Please note that 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 and how to add an action to this link. The example creates two PDF documents, which are linked together through the links associated with the GoToR action.
    Dim caption As String = "Example: AddLinkAnnotation"
    Dim oGdPicturePDF As New GdPicturePDF()
    Dim failure As Boolean = True
    Dim textSize As Single = 12, textWidth As Single = 0, textHeight As Single = 0
    Dim status As GdPictureStatus = oGdPicturePDF.NewPDF()
    If status = GdPictureStatus.OK Then
        'Creating of the pdf1.pdf.
        oGdPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
        oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
        Dim fontResName As String = oGdPicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica)
        status = oGdPicturePDF.GetStat()
        If status = GdPictureStatus.OK Then
            If (oGdPicturePDF.NewPage(21, 29.7F) = GdPictureStatus.OK) AndAlso
               (oGdPicturePDF.SetFillColor(255, 0, 0) = GdPictureStatus.OK) AndAlso
               (oGdPicturePDF.SetTextSize(textSize) = GdPictureStatus.OK) Then
                Dim text As String = "Navigate to pdf2.pdf"
                textWidth = oGdPicturePDF.GetTextWidth(fontResName, textSize, text)
                status = oGdPicturePDF.GetStat()
                If status = GdPictureStatus.OK Then
                    textHeight = oGdPicturePDF.GetTextHeight(fontResName, textSize, True)
                    status = oGdPicturePDF.GetStat()
                End If
                If (status = GdPictureStatus.OK) AndAlso
                    (oGdPicturePDF.DrawTextBox(fontResName, 1, 1, textWidth + 1, textHeight + 1, TextAlignment.TextAlignmentNear, TextAlignment.TextAlignmentNear, text) = GdPictureStatus.OK) Then
                    Dim linkIdx As Integer = oGdPicturePDF.AddLinkAnnotation(1, 1, textWidth, textHeight, True, 0, 0, 255)
                    status = oGdPicturePDF.GetStat()
                    If status = GdPictureStatus.OK Then
                        Dim actionID As Integer = oGdPicturePDF.NewActionGoToR(PdfDestinationType.DestinationTypeXYZ, "pdf2.pdf", False, 1, 0, 0, 0, 0, 1)
                        status = oGdPicturePDF.GetStat()
                        If status = GdPictureStatus.OK Then
                            If (oGdPicturePDF.SetAnnotationAction(linkIdx, actionID) = GdPictureStatus.OK) AndAlso
                               (oGdPicturePDF.SaveToFile("pdf1.pdf") = GdPictureStatus.OK) AndAlso (oGdPicturePDF.CloseDocument() = GdPictureStatus.OK) Then
                                MessageBox.Show("The pdf1.pdf has been successfully created with the link that guides to the pdf2.pdf.", caption)
                                failure = False
                            End If
                        End If
                    End If
                End If
            End If
        End If
    End If
    If failure Then
        MessageBox.Show("The example HAS NOT been successfully followed." + vbCrLf + "The last known error status is " + oGdPicturePDF.GetStat().ToString(), caption)
    Else
        failure = True
        status = oGdPicturePDF.NewPDF()
        If status = GdPictureStatus.OK Then
            'Creating of the pdf2.pdf.
            oGdPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
            oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
            Dim fontResName As String = oGdPicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica)
            status = oGdPicturePDF.GetStat()
            If status = GdPictureStatus.OK Then
                If (oGdPicturePDF.NewPage(21, 29.7F) = GdPictureStatus.OK) AndAlso
                   (oGdPicturePDF.SetFillColor(255, 0, 0) = GdPictureStatus.OK) AndAlso
                   (oGdPicturePDF.SetTextSize(textSize) = GdPictureStatus.OK) Then
                    Dim text As String = "Navigate to pdf1.pdf"
                    textWidth = oGdPicturePDF.GetTextWidth(fontResName, textSize, text)
                    status = oGdPicturePDF.GetStat()
                    If status = GdPictureStatus.OK Then
                        textHeight = oGdPicturePDF.GetTextHeight(fontResName, textSize, True)
                        status = oGdPicturePDF.GetStat()
                    End If
                    If (status = GdPictureStatus.OK) AndAlso
                       (oGdPicturePDF.DrawTextBox(fontResName, 1, 1, textWidth + 1, textHeight + 1, TextAlignment.TextAlignmentNear, TextAlignment.TextAlignmentNear, text) = GdPictureStatus.OK) Then
                        Dim linkIdx As Integer = oGdPicturePDF.AddLinkAnnotation(1, 1, textWidth, textHeight, True, 0, 0, 255)
                        status = oGdPicturePDF.GetStat()
                        If status = GdPictureStatus.OK Then
                            Dim actionID As Integer = oGdPicturePDF.NewActionGoToR(PdfDestinationType.DestinationTypeXYZ, "pdf1.pdf", False, 1, 0, 0, 0, 0, 1)
                            status = oGdPicturePDF.GetStat()
                            If status = GdPictureStatus.OK Then
                                If (oGdPicturePDF.SetAnnotationAction(linkIdx, actionID) = GdPictureStatus.OK) AndAlso
                                   (oGdPicturePDF.SaveToFile("pdf2.pdf") = GdPictureStatus.OK) AndAlso (oGdPicturePDF.CloseDocument() = GdPictureStatus.OK) Then
                                    MessageBox.Show("The pdf2.pdf has been successfully created with the link that guides to the pdf1.pdf.", caption)
                                    failure = False
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        End If
        If failure Then
            MessageBox.Show("The example HAS NOT been successfully followed." + vbCrLf + "The last known error status is " + oGdPicturePDF.GetStat(), caption)
        Else
            MessageBox.Show("The example HAS been successfully followed." + vbCrLf + "Both newly created PDF documents are linked together.", caption)
        End If
    End If
    oGdPicturePDF.Dispose()
    string caption = "Example: AddLinkAnnotation";
    GdPicturePDF oGdPicturePDF = new GdPicturePDF();
    bool failure = true;
    float textSize = 12, textWidth = 0, textHeight = 0;
    GdPictureStatus status = oGdPicturePDF.NewPDF();
    if (status == GdPictureStatus.OK)
    {
        //Creating of the pdf1.pdf.
        oGdPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
        oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
        string fontResName = oGdPicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica);
        status = oGdPicturePDF.GetStat();
        if (status == GdPictureStatus.OK)
        {
            if ((oGdPicturePDF.NewPage(21, 29.7f) == GdPictureStatus.OK) &&
                (oGdPicturePDF.SetFillColor(255, 0, 0) == GdPictureStatus.OK) &&
                (oGdPicturePDF.SetTextSize(textSize) == GdPictureStatus.OK))
            {
                string text = "Navigate to pdf2.pdf";
                textWidth = oGdPicturePDF.GetTextWidth(fontResName, textSize, text);
                status = oGdPicturePDF.GetStat();
                if (status == GdPictureStatus.OK)
                {
                    textHeight = oGdPicturePDF.GetTextHeight(fontResName, textSize, true);
                    status = oGdPicturePDF.GetStat();
                }
                if ((status == GdPictureStatus.OK) &&
                    (oGdPicturePDF.DrawTextBox(fontResName, 1, 1, textWidth + 1, textHeight + 1, TextAlignment.TextAlignmentNear, TextAlignment.TextAlignmentNear, text) == GdPictureStatus.OK))
                {
                    int linkIdx = oGdPicturePDF.AddLinkAnnotation(1, 1, textWidth, textHeight, true, 0, 0, 255);
                    status = oGdPicturePDF.GetStat();
                    if (status == GdPictureStatus.OK)
                    {
                        int actionID = oGdPicturePDF.NewActionGoToR(PdfDestinationType.DestinationTypeXYZ, "pdf2.pdf", false, 1, 0, 0, 0, 0, 1);
                        status = oGdPicturePDF.GetStat();
                        if (status == GdPictureStatus.OK)
                        {
                            if ((oGdPicturePDF.SetAnnotationAction(linkIdx, actionID) == GdPictureStatus.OK) &&
                                (oGdPicturePDF.SaveToFile("pdf1.pdf") == GdPictureStatus.OK) && (oGdPicturePDF.CloseDocument() == GdPictureStatus.OK))
                            {
                                MessageBox.Show("The pdf1.pdf has been successfully created with the link that guides to the pdf2.pdf.", caption);
                                failure = false;
                            }
                        }
                    }
                }
            }
        }
    }
    if (failure)
        MessageBox.Show("The example HAS NOT been successfully followed.\nThe last known error status is " + oGdPicturePDF.GetStat().ToString(), caption);
    else
    {
        failure = true;
        status = oGdPicturePDF.NewPDF();
        if (status == GdPictureStatus.OK)
        {
            //Creating of the pdf2.pdf.
            oGdPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
            oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
            string fontResName = oGdPicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica);
            status = oGdPicturePDF.GetStat();
            if (status == GdPictureStatus.OK)
            {
                if ((oGdPicturePDF.NewPage(21, 29.7f) == GdPictureStatus.OK) &&
                    (oGdPicturePDF.SetFillColor(255, 0, 0) == GdPictureStatus.OK) &&
                    (oGdPicturePDF.SetTextSize(textSize) == GdPictureStatus.OK))
                {
                    string text = "Navigate to pdf1.pdf";
                    textWidth = oGdPicturePDF.GetTextWidth(fontResName, textSize, text);
                    status = oGdPicturePDF.GetStat();
                    if (status == GdPictureStatus.OK)
                    {
                        textHeight = oGdPicturePDF.GetTextHeight(fontResName, textSize, true);
                        status = oGdPicturePDF.GetStat();
                    }
                    if ((status == GdPictureStatus.OK) &&
                        (oGdPicturePDF.DrawTextBox(fontResName, 1, 1, textWidth + 1, textHeight + 1, TextAlignment.TextAlignmentNear, TextAlignment.TextAlignmentNear, text) == GdPictureStatus.OK))
                    {
                        int linkIdx = oGdPicturePDF.AddLinkAnnotation(1, 1, textWidth, textHeight, true, 0, 0, 255);
                        status = oGdPicturePDF.GetStat();
                        if (status == GdPictureStatus.OK)
                        {
                            int actionID = oGdPicturePDF.NewActionGoToR(PdfDestinationType.DestinationTypeXYZ, "pdf1.pdf", false, 1, 0, 0, 0, 0, 1);
                            status = oGdPicturePDF.GetStat();
                            if (status == GdPictureStatus.OK)
                            {
                                if ((oGdPicturePDF.SetAnnotationAction(linkIdx, actionID) == GdPictureStatus.OK) &&
                                    (oGdPicturePDF.SaveToFile("pdf2.pdf") == GdPictureStatus.OK) && (oGdPicturePDF.CloseDocument() == GdPictureStatus.OK))
                                {
                                    MessageBox.Show("The pdf2.pdf has been successfully created with the link that guides to the pdf1.pdf.", caption);
                                    failure = false;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (failure)
            MessageBox.Show("The example HAS NOT been successfully followed.\nThe last known error status is " + oGdPicturePDF.GetStat(), caption);
        else
            MessageBox.Show("The example HAS been successfully followed.\nBoth newly created PDF documents are linked together.", caption);
    }
    oGdPicturePDF.Dispose();
    See Also