The 0-based index of the required annotation within the current page. It must be a value from 0 to GdPicturePDF.GetAnnotationCount-1.
Output parameter. The horizontal (X) coordinate of the closest point to the currently defined origin, where the annotation's bounding box is located. The returned value is expressed in the current units specified by the SetMeasurementUnit method and it is related to the current page.
Output parameter. The vertical (Y) coordinate of the closest point to the currently defined origin, where the annotation's bounding box is located. The returned value expressed is in the current units used in the PDF document and it is related to the current page.
Output parameter. The width of the annotation's bounding box. The returned value is expressed in the current units specified by the SetMeasurementUnit method.
Output parameter. The height of the annotation's bounding box. The returned value is expressed in the current units specified by the SetMeasurementUnit method.
Example





In This Topic
GdPicture14 Namespace / GdPicturePDF Class / GetAnnotationRect Method

GetAnnotationRect Method (GdPicturePDF)

In This Topic
Returns the rectangle (the bounding box) of a required annotation object specified by its index related to the currently selected page of the loaded PDF document. This rectangle defines the location of the annotation on the page expressed in the current units used in this document with respect to the currently defined origin.

You can use the GdPicturePDF.SetMeasurementUnit method to reset the units and the GdPicturePDF.SetOrigin method to reset the origin's location according to your preference.

Syntax
'Declaration
 
Public Function GetAnnotationRect( _
   ByVal AnnotationIdx As Integer, _
   ByRef Left As Single, _
   ByRef Top As Single, _
   ByRef Width As Single, _
   ByRef Height As Single _
) As GdPictureStatus
public GdPictureStatus GetAnnotationRect( 
   int AnnotationIdx,
   ref float Left,
   ref float Top,
   ref float Width,
   ref float Height
)
public function GetAnnotationRect( 
    AnnotationIdx: Integer;
   var  Left: Single;
   var  Top: Single;
   var  Width: Single;
   var  Height: Single
): GdPictureStatus; 
public function GetAnnotationRect( 
   AnnotationIdx : int,
   Left : float,
   Top : float,
   Width : float,
   Height : float
) : GdPictureStatus;
public: GdPictureStatus GetAnnotationRect( 
   int AnnotationIdx,
   ref float Left,
   ref float Top,
   ref float Width,
   ref float Height
) 
public:
GdPictureStatus GetAnnotationRect( 
   int AnnotationIdx,
   float% Left,
   float% Top,
   float% Width,
   float% Height
) 

Parameters

AnnotationIdx
The 0-based index of the required annotation within the current page. It must be a value from 0 to GdPicturePDF.GetAnnotationCount-1.
Left
Output parameter. The horizontal (X) coordinate of the closest point to the currently defined origin, where the annotation's bounding box is located. The returned value is expressed in the current units specified by the SetMeasurementUnit method and it is related to the current page.
Top
Output parameter. The vertical (Y) coordinate of the closest point to the currently defined origin, where the annotation's bounding box is located. The returned value expressed is in the current units used in the PDF document and it is related to the current page.
Width
Output parameter. The width of the annotation's bounding box. The returned value is expressed in the current units specified by the SetMeasurementUnit method.
Height
Output parameter. The height of the annotation's bounding box. The returned value is expressed in the current units specified by the SetMeasurementUnit method.

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.

Please always ensure that you have selected the correct page using the GdPicturePDF.SelectPage method before applying an annotation index.

Be aware that the values of the 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 retrieve the bounding box attributes and some other properties of all stamp annotation objects within the PDF document.
Dim caption As String = "Example: GetAnnotationRect"
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("test.pdf", False)
If status = GdPictureStatus.OK Then
    Dim message As String = ""
    Dim pageCount As Integer = gdpicturePDF.GetPageCount()
    For i As Integer = 1 To pageCount
        status = gdpicturePDF.SelectPage(i)
        If status = GdPictureStatus.OK Then
            message = message + "The page nr." + i.ToString()
            Dim annotCount As Integer = gdpicturePDF.GetAnnotationCount()
            status = gdpicturePDF.GetStat()
            If status = GdPictureStatus.OK Then
                If annotCount = 0 Then
                    message = message + " does not contain any annotations."
                Else
                    Dim annotSubType As String = ""
                    Dim color As Color = Color.Black, fillColor As Color = Color.Black
                    Dim opacity As Byte = 0
                    Dim l As Single = 0, t As Single = 0, w As Single = 0, h As Single = 0
                    For j As Integer = 0 To annotCount - 1
                        annotSubType = gdpicturePDF.GetAnnotationSubType(j)
                        If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                            If annotSubType.Equals("Stamp") Then
                                message = message + vbCrLf + "AnnotID: " + j.ToString()
                                message = message + vbCrLf + "    color: "
                                color = gdpicturePDF.GetAnnotationColor(j)
                                status = gdpicturePDF.GetStat()
                                If status = GdPictureStatus.OK Then message = message + color.ToString() Else message = message + status.ToString()
                                message = message + "    fill color: "
                                fillColor = gdpicturePDF.GetAnnotationFillColor(j)
                                status = gdpicturePDF.GetStat()
                                If status = GdPictureStatus.OK Then message = message + fillColor.ToString() Else message = message + status.ToString()
                                message = message + "    opacity: "
                                opacity = gdpicturePDF.GetAnnotationOpacity(j)
                                status = gdpicturePDF.GetStat()
                                If status = GdPictureStatus.OK Then message = message + opacity.ToString() Else message = message + status.ToString()
                                message = message + "    rectangle: "
                                status = gdpicturePDF.GetAnnotationRect(j, l, t, w, h)
                                If status = GdPictureStatus.OK Then message = message + "[" + l.ToString() + "," + t.ToString() + " ; w:" + w.ToString() + " h:" + h.ToString() + "]" Else message = message + status.ToString()
                            End If
                        Else
                            message = message + vbCrLf + "The GetAnnotationSubType() method has failed with the status: " + status.ToString()
                        End If
                    Next
                End If
            Else
                message = message + ": the GetAnnotationCount() method has failed with the status: " + status.ToString()
            End If
            message = message + vbCrLf
        Else
            message = message + "The SelectPage(" + i.ToString() + ") method has failed with the status: " + status.ToString() + vbCrLf
        End If
    Next
    MessageBox.Show(message, caption)
Else
    MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: GetAnnotationRect";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.LoadFromFile("test.pdf", false);
if (status == GdPictureStatus.OK)
{
    string message = "";
    int pageCount = gdpicturePDF.GetPageCount();
    for (int i = 1; i <= pageCount; i++)
    {
        status = gdpicturePDF.SelectPage(i);
        if (status == GdPictureStatus.OK)
        {
            message = message + "The page nr." + i.ToString();
            int annotCount = gdpicturePDF.GetAnnotationCount();
            status = gdpicturePDF.GetStat();
            if (status == GdPictureStatus.OK)
            {
                if (annotCount == 0)
                {
                    message = message + " does not contain any annotations.";
                }
                else
                {
                    string annotSubType = "";
                    Color color = Color.Black, fillColor = Color.Black;
                    byte opacity = 0;
                    float l = 0, t = 0, w = 0, h = 0;
                    for (int j = 0; j < annotCount; j++)
                    {
                        annotSubType = gdpicturePDF.GetAnnotationSubType(j);
                        if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                        {
                            if (annotSubType.Equals("Stamp"))
                            {
                                message = message + "\nAnnotID: " + j.ToString();
            
                                message = message + "\n    color: ";
                                color = gdpicturePDF.GetAnnotationColor(j);
                                status = gdpicturePDF.GetStat();
                                if (status == GdPictureStatus.OK) message = message + color;
                                else message = message + status.ToString();
            
                                message = message + "    fill color: ";
                                fillColor = gdpicturePDF.GetAnnotationFillColor(j);
                                status = gdpicturePDF.GetStat();
                                if (status == GdPictureStatus.OK) message = message + fillColor;
                                else message = message + status.ToString();
            
                                message = message + "    opacity: ";
                                opacity = gdpicturePDF.GetAnnotationOpacity(j);
                                status = gdpicturePDF.GetStat();
                                if (status == GdPictureStatus.OK) message = message + opacity.ToString();
                                else message = message + status.ToString();
            
                                message = message + "    rectangle: ";
                                status = gdpicturePDF.GetAnnotationRect(j, ref l, ref t, ref w, ref h);
                                if (status == GdPictureStatus.OK) message = message + "[" + l.ToString() + "," + t.ToString() + " ; w:" + w.ToString() + " h:" + h.ToString() + "]";
                                else message = message + status.ToString();
                            }
                        }
                        else
                        {
                            message = message + "\nThe GetAnnotationSubType() method has failed with the status: " + status.ToString();
                        }
                    }
                }
            }
            else
                message = message + ": the GetAnnotationCount() method has failed with the status: " + status.ToString();
            
            message = message + "\n";
        }
        else
            message = message + "The SelectPage(" + i.ToString() + ") method has failed with the status: " + status.ToString() + "\n";
    }
    MessageBox.Show(message, caption);
}
else
{
    MessageBox.Show("The file can't be loaded.", caption);
}
gdpicturePDF.Dispose();
See Also