GdPicture.NET.14.API
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 GdPicturePDF.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 GdPicturePDF.GetAnnotationCount-1 related to the currently selected page. The GdPicturePDF.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 GdPicturePDF.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 GdPicturePDF.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 GdPicturePDF.SetMeasurementUnit method according to the current coordinate space defined by the GdPicturePDF.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 gdpicturePDF 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 = gdpicturePDF.NewPDF()
If status = GdPictureStatus.OK Then
    'Creating of the pdf1.pdf.
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
    Dim fontResName As String = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica)
    status = gdpicturePDF.GetStat()
    If status = GdPictureStatus.OK Then
        If (gdpicturePDF.NewPage(21, 29.7F) = GdPictureStatus.OK) AndAlso
           (gdpicturePDF.SetFillColor(255, 0, 0) = GdPictureStatus.OK) AndAlso
           (gdpicturePDF.SetTextSize(textSize) = GdPictureStatus.OK) Then
            Dim text As String = "Navigate to pdf2.pdf"
            textWidth = gdpicturePDF.GetTextWidth(fontResName, textSize, text)
            status = gdpicturePDF.GetStat()
            If status = GdPictureStatus.OK Then
                textHeight = gdpicturePDF.GetTextHeight(fontResName, textSize, True)
                status = gdpicturePDF.GetStat()
            End If
            If (status = GdPictureStatus.OK) AndAlso
                (gdpicturePDF.DrawTextBox(fontResName, 1, 1, textWidth + 1, textHeight + 1, TextAlignment.TextAlignmentNear, TextAlignment.TextAlignmentNear, text) = GdPictureStatus.OK) Then
                Dim linkIdx As Integer = gdpicturePDF.AddLinkAnnotation(1, 1, textWidth, textHeight, True, 0, 0, 255)
                status = gdpicturePDF.GetStat()
                If status = GdPictureStatus.OK Then
                    Dim actionID As Integer = gdpicturePDF.NewActionGoToR(PdfDestinationType.DestinationTypeXYZ, "pdf2.pdf", False, 1, 0, 0, 0, 0, 1)
                    status = gdpicturePDF.GetStat()
                    If status = GdPictureStatus.OK Then
                        If (gdpicturePDF.SetAnnotationAction(linkIdx, actionID) = GdPictureStatus.OK) AndAlso
                           (gdpicturePDF.SaveToFile("pdf1.pdf") = GdPictureStatus.OK) AndAlso (gdpicturePDF.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 " + gdpicturePDF.GetStat().ToString(), caption)
Else
    failure = True
    status = gdpicturePDF.NewPDF()
    If status = GdPictureStatus.OK Then
        'Creating of the pdf2.pdf.
        gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
        gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
        Dim fontResName As String = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica)
        status = gdpicturePDF.GetStat()
        If status = GdPictureStatus.OK Then
            If (gdpicturePDF.NewPage(21, 29.7F) = GdPictureStatus.OK) AndAlso
               (gdpicturePDF.SetFillColor(255, 0, 0) = GdPictureStatus.OK) AndAlso
               (gdpicturePDF.SetTextSize(textSize) = GdPictureStatus.OK) Then
                Dim text As String = "Navigate to pdf1.pdf"
                textWidth = gdpicturePDF.GetTextWidth(fontResName, textSize, text)
                status = gdpicturePDF.GetStat()
                If status = GdPictureStatus.OK Then
                    textHeight = gdpicturePDF.GetTextHeight(fontResName, textSize, True)
                    status = gdpicturePDF.GetStat()
                End If
                If (status = GdPictureStatus.OK) AndAlso
                   (gdpicturePDF.DrawTextBox(fontResName, 1, 1, textWidth + 1, textHeight + 1, TextAlignment.TextAlignmentNear, TextAlignment.TextAlignmentNear, text) = GdPictureStatus.OK) Then
                    Dim linkIdx As Integer = gdpicturePDF.AddLinkAnnotation(1, 1, textWidth, textHeight, True, 0, 0, 255)
                    status = gdpicturePDF.GetStat()
                    If status = GdPictureStatus.OK Then
                        Dim actionID As Integer = gdpicturePDF.NewActionGoToR(PdfDestinationType.DestinationTypeXYZ, "pdf1.pdf", False, 1, 0, 0, 0, 0, 1)
                        status = gdpicturePDF.GetStat()
                        If status = GdPictureStatus.OK Then
                            If (gdpicturePDF.SetAnnotationAction(linkIdx, actionID) = GdPictureStatus.OK) AndAlso
                               (gdpicturePDF.SaveToFile("pdf2.pdf") = GdPictureStatus.OK) AndAlso (gdpicturePDF.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 " + gdpicturePDF.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
gdpicturePDF.Dispose()
string caption = "Example: AddLinkAnnotation";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
bool failure = true;
float textSize = 12, textWidth = 0, textHeight = 0;
GdPictureStatus status = gdpicturePDF.NewPDF();
if (status == GdPictureStatus.OK)
{
    //Creating of the pdf1.pdf.
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
    string fontResName = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica);
    status = gdpicturePDF.GetStat();
    if (status == GdPictureStatus.OK)
    {
        if ((gdpicturePDF.NewPage(21, 29.7f) == GdPictureStatus.OK) &&
            (gdpicturePDF.SetFillColor(255, 0, 0) == GdPictureStatus.OK) &&
            (gdpicturePDF.SetTextSize(textSize) == GdPictureStatus.OK))
        {
            string text = "Navigate to pdf2.pdf";
            textWidth = gdpicturePDF.GetTextWidth(fontResName, textSize, text);
            status = gdpicturePDF.GetStat();
            if (status == GdPictureStatus.OK)
            {
                textHeight = gdpicturePDF.GetTextHeight(fontResName, textSize, true);
                status = gdpicturePDF.GetStat();
            }
            if ((status == GdPictureStatus.OK) &&
                (gdpicturePDF.DrawTextBox(fontResName, 1, 1, textWidth + 1, textHeight + 1, TextAlignment.TextAlignmentNear, TextAlignment.TextAlignmentNear, text) == GdPictureStatus.OK))
            {
                int linkIdx = gdpicturePDF.AddLinkAnnotation(1, 1, textWidth, textHeight, true, 0, 0, 255);
                status = gdpicturePDF.GetStat();
                if (status == GdPictureStatus.OK)
                {
                    int actionID = gdpicturePDF.NewActionGoToR(PdfDestinationType.DestinationTypeXYZ, "pdf2.pdf", false, 1, 0, 0, 0, 0, 1);
                    status = gdpicturePDF.GetStat();
                    if (status == GdPictureStatus.OK)
                    {
                        if ((gdpicturePDF.SetAnnotationAction(linkIdx, actionID) == GdPictureStatus.OK) &&
                            (gdpicturePDF.SaveToFile("pdf1.pdf") == GdPictureStatus.OK) && (gdpicturePDF.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 " + gdpicturePDF.GetStat().ToString(), caption);
else
{
    failure = true;
    status = gdpicturePDF.NewPDF();
    if (status == GdPictureStatus.OK)
    {
        //Creating of the pdf2.pdf.
        gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
        gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
        string fontResName = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica);
        status = gdpicturePDF.GetStat();
        if (status == GdPictureStatus.OK)
        {
            if ((gdpicturePDF.NewPage(21, 29.7f) == GdPictureStatus.OK) &&
                (gdpicturePDF.SetFillColor(255, 0, 0) == GdPictureStatus.OK) &&
                (gdpicturePDF.SetTextSize(textSize) == GdPictureStatus.OK))
            {
                string text = "Navigate to pdf1.pdf";
                textWidth = gdpicturePDF.GetTextWidth(fontResName, textSize, text);
                status = gdpicturePDF.GetStat();
                if (status == GdPictureStatus.OK)
                {
                    textHeight = gdpicturePDF.GetTextHeight(fontResName, textSize, true);
                    status = gdpicturePDF.GetStat();
                }
                if ((status == GdPictureStatus.OK) &&
                    (gdpicturePDF.DrawTextBox(fontResName, 1, 1, textWidth + 1, textHeight + 1, TextAlignment.TextAlignmentNear, TextAlignment.TextAlignmentNear, text) == GdPictureStatus.OK))
                {
                    int linkIdx = gdpicturePDF.AddLinkAnnotation(1, 1, textWidth, textHeight, true, 0, 0, 255);
                    status = gdpicturePDF.GetStat();
                    if (status == GdPictureStatus.OK)
                    {
                        int actionID = gdpicturePDF.NewActionGoToR(PdfDestinationType.DestinationTypeXYZ, "pdf1.pdf", false, 1, 0, 0, 0, 0, 1);
                        status = gdpicturePDF.GetStat();
                        if (status == GdPictureStatus.OK)
                        {
                            if ((gdpicturePDF.SetAnnotationAction(linkIdx, actionID) == GdPictureStatus.OK) &&
                                (gdpicturePDF.SaveToFile("pdf2.pdf") == GdPictureStatus.OK) && (gdpicturePDF.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 " + gdpicturePDF.GetStat(), caption);
    else
        MessageBox.Show("The example HAS been successfully followed.\nBoth newly created PDF documents are linked together.", caption);
}
gdpicturePDF.Dispose();
See Also