GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / AddLinkToWebAnnotation 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 uniform resource identifier to resolve, encoded in 7-bit ASCII. In other words, the web destination of this link annotation, for example "http://www.gdpicture.com".
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
AddLinkToWebAnnotation 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 the action of the type URI. The destination of the assigned action is the URI (web destination) you have specified.

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 AddLinkToWebAnnotation( _
   ByVal Left As Single, _
   ByVal Top As Single, _
   ByVal Width As Single, _
   ByVal Height As Single, _
   ByVal URI As String, _
   ByVal Borders As Boolean, _
   ByVal Red As Byte, _
   ByVal Green As Byte, _
   ByVal Blue As Byte _
) As Integer
public int AddLinkToWebAnnotation( 
   float Left,
   float Top,
   float Width,
   float Height,
   string URI,
   bool Borders,
   byte Red,
   byte Green,
   byte Blue
)
public function AddLinkToWebAnnotation( 
    Left: Single;
    Top: Single;
    Width: Single;
    Height: Single;
    URI: String;
    Borders: Boolean;
    Red: Byte;
    Green: Byte;
    Blue: Byte
): Integer; 
public function AddLinkToWebAnnotation( 
   Left : float,
   Top : float,
   Width : float,
   Height : float,
   URI : String,
   Borders : boolean,
   Red : byte,
   Green : byte,
   Blue : byte
) : int;
public: int AddLinkToWebAnnotation( 
   float Left,
   float Top,
   float Width,
   float Height,
   string* URI,
   bool Borders,
   byte Red,
   byte Green,
   byte Blue
) 
public:
int AddLinkToWebAnnotation( 
   float Left,
   float Top,
   float Width,
   float Height,
   String^ URI,
   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.
URI
The uniform resource identifier to resolve, encoded in 7-bit ASCII. In other words, the web destination of this link annotation, for example "http://www.gdpicture.com".
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 web page.
Dim caption As String = "Example: AddLinkToWebAnnotation"
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
If (gdpicturePDF.NewPDF() = GdPictureStatus.OK) AndAlso
   (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) Then
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
    gdpicturePDF.SelectPage(1)
    Dim textSize As Single = 20
    Dim text As String = "Navigate to www.gdpicture.com"
    Dim fontResName As String = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica)
    If (gdpicturePDF.GetStat() = GdPictureStatus.OK) AndAlso
       (gdpicturePDF.SetFillColor(255, 140, 0) = GdPictureStatus.OK) AndAlso
       (gdpicturePDF.SetTextSize(textSize) = GdPictureStatus.OK) Then
        Dim textW As Single = gdpicturePDF.GetTextWidth(fontResName, textSize, text)
        Dim status1 As GdPictureStatus = gdpicturePDF.GetStat()
        Dim textH As Single = gdpicturePDF.GetTextHeight(fontResName, textSize, False)
        Dim status2 As GdPictureStatus = gdpicturePDF.GetStat()
        If (status1 = GdPictureStatus.OK) AndAlso (status2 = GdPictureStatus.OK) Then
            If gdpicturePDF.DrawText(fontResName, 5, 10 + textH, text) = GdPictureStatus.OK Then
                'Do not forget to select the required page before adding an annotation, the currently selected page is 1.
                Dim annotID As Integer = gdpicturePDF.AddLinkToWebAnnotation(5, 10 - textH / 2, textW, 2 * textH, "www.gdpicture.com", True, 0, 0, 255)
                'Each valid annotID should be >= 0, but it is recommended to check the error status, not the returned ID.
                If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                    Dim annotType As String = gdpicturePDF.GetAnnotationType(annotID)
                    status1 = gdpicturePDF.GetStat()
                    Dim annotSubtype As String = gdpicturePDF.GetAnnotationSubType(annotID)
                    status2 = gdpicturePDF.GetStat()
                    Dim message As String = "The annotation has been created with the ID = " + annotID.ToString() + "." + vbCrLf + "type: "
                    If status1 = GdPictureStatus.OK Then message = message + annotType Else message = message + status1.ToString()
                    message = message + "    subtype: "
                    If status2 = GdPictureStatus.OK Then message = message + annotSubtype Else message = message + status2.ToString()
                    If gdpicturePDF.SaveToFile("linkwebannot.pdf") = GdPictureStatus.OK Then
                        message = message + vbCrLf + "The file has been saved."
                    Else
                        message = message + vbCrLf + "The file can't be saved. Status: " + gdpicturePDF.GetStat().ToString()
                    End If
                    MessageBox.Show(message, caption)
                Else
                    MessageBox.Show("The AddLinkToWebAnnotation() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
                End If
            Else
                MessageBox.Show("The DrawText() method has failed with the status: " + gdpicturePDF.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: " + gdpicturePDF.GetStat().ToString(), caption)
    End If
Else
    MessageBox.Show("The file can't be created.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: AddLinkToWebAnnotation";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if ((gdpicturePDF.NewPDF() == GdPictureStatus.OK) &&
    (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK))
{
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
    gdpicturePDF.SelectPage(1);
    float textSize = 20;
    string text = "Navigate to www.gdpicture.com";
    string fontResName = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica);
    if ((gdpicturePDF.GetStat() == GdPictureStatus.OK) &&
        (gdpicturePDF.SetFillColor(255, 140, 0) == GdPictureStatus.OK) &&
        (gdpicturePDF.SetTextSize(textSize) == GdPictureStatus.OK))
    {
        float textW = gdpicturePDF.GetTextWidth(fontResName, textSize, text);
        GdPictureStatus status1 = gdpicturePDF.GetStat();
        float textH = gdpicturePDF.GetTextHeight(fontResName, textSize, false);
        GdPictureStatus status2 = gdpicturePDF.GetStat();
        if ((status1 == GdPictureStatus.OK) && (status2 == GdPictureStatus.OK))
        {
            if (gdpicturePDF.DrawText(fontResName, 5, 10 + textH, text) == GdPictureStatus.OK)
            {
                //Do not forget to select the required page before adding an annotation, the currently selected page is 1.
                int annotID = gdpicturePDF.AddLinkToWebAnnotation(5, 10-textH/2, textW, 2*textH, "www.gdpicture.com", true, 0, 0, 255);
                //Each valid annotID should be >= 0, but it is recommended to check the error status, not the returned ID.
                if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                {
                    string annotType = gdpicturePDF.GetAnnotationType(annotID);
                    status1 = gdpicturePDF.GetStat();
                    string annotSubtype = gdpicturePDF.GetAnnotationSubType(annotID);
                    status2 = gdpicturePDF.GetStat();
                    string message = "The annotation has been created with the ID = " + annotID.ToString() + ".\ntype: ";
                    if (status1 == GdPictureStatus.OK) message = message + annotType; else message = message + status1.ToString();
                    message = message + "    subtype: ";
                    if (status2 == GdPictureStatus.OK) message = message + annotSubtype; else message = message + status2.ToString();
                    if (gdpicturePDF.SaveToFile("linkwebannot.pdf") == GdPictureStatus.OK)
                        message = message + "\nThe file has been saved.";
                    else
                        message = message + "\nThe file can't be saved. Status: " + gdpicturePDF.GetStat().ToString();
                    MessageBox.Show(message, caption);
                }
                else
                    MessageBox.Show("The AddLinkToWebAnnotation() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
            }
            else
                MessageBox.Show("The DrawText() method has failed with the status: " + gdpicturePDF.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: " + gdpicturePDF.GetStat().ToString(), caption);
}
else
    MessageBox.Show("The file can't be created.", caption);
gdpicturePDF.Dispose();
See Also