GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / GetAnnotationName Method
The 0-based index of the required annotation within the current page. It must be a value from 0 to GdPicturePDF.GetAnnotationCount-1.
Example





In This Topic
GetAnnotationName Method (GdPicturePDF)
In This Topic
Returns the annotation name of a required annotation object specified by its index related to the currently selected page of the loaded PDF document. It is a text string, corresponding to the NM entry in the annotation dictionary (see PDF Reference, Section "Annotation Dictionaries"), uniquely identifying the annotation among all the annotations on its page. You can use this attribute, for example, to precisely identify the annotation in third-party software.
Syntax
'Declaration
 
Public Function GetAnnotationName( _
   ByVal AnnotationIdx As Integer _
) As String
public string GetAnnotationName( 
   int AnnotationIdx
)
public function GetAnnotationName( 
    AnnotationIdx: Integer
): String; 
public function GetAnnotationName( 
   AnnotationIdx : int
) : String;
public: string* GetAnnotationName( 
   int AnnotationIdx
) 
public:
String^ GetAnnotationName( 
   int AnnotationIdx
) 

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.

Return Value

The annotation name of the specified annotation object. 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 applying an annotation index.

Be aware that this attribute is optional, for more details please refer to the NM entry in the annotation dictionary in the PDF Reference.

Example
How to get the value of the annotation name attribute for further use.
Dim caption As String = "Example: GetAnnotationName"
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("test.pdf", False)
If status = GdPictureStatus.OK Then
    Dim annotname As String = Nothing
    Dim annotCount As Integer = 0
    Dim pageCount As Integer = gdpicturePDF.GetPageCount()
    For i As Integer = 1 To pageCount
        If gdpicturePDF.SelectPage(i) <> GdPictureStatus.OK Then Exit For
        annotCount = gdpicturePDF.GetAnnotationCount()
        If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then Exit For
        If annotCount = 0 Then Continue For
        For j As Integer = 0 To annotCount - 1
            annotname = gdpicturePDF.GetAnnotationName(j)
            If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                If annotname.Equals("required_annotation_name") Then status = gdpicturePDF.SetAnnotationOpacity(j, 0)
                If status <> GdPictureStatus.OK Then Exit For
            ElseIf gdpicturePDF.GetStat() <> GdPictureStatus.PropertyNotFound Then
                'The annotation name attribut is optional.
                Exit For
            End If
        Next
        If (gdpicturePDF.GetStat() <> GdPictureStatus.OK) AndAlso (gdpicturePDF.GetStat() <> GdPictureStatus.PropertyNotFound) Then Exit For
    Next
    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
        status = gdpicturePDF.SaveToFile("test_annotnames.pdf")
        If status = 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 can't be saved. Status: " + status.ToString(), caption)
        End If
    Else
        MessageBox.Show("The example has failed. Status: " + gdpicturePDF.GetStat().ToString(), caption)
    End If
Else
    MessageBox.Show("The file can't be loaded. Status: " + status.ToString(), caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: GetAnnotationName";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.LoadFromFile("test.pdf", false);
if (status == GdPictureStatus.OK)
{
    string annotname = null;
    int annotCount = 0;
    int pageCount = gdpicturePDF.GetPageCount();
    for (int i = 1; i <= pageCount; i++)
    {
        if (gdpicturePDF.SelectPage(i) != GdPictureStatus.OK) break;
        annotCount = gdpicturePDF.GetAnnotationCount();
        if (gdpicturePDF.GetStat() != GdPictureStatus.OK) break;
        if (annotCount == 0) continue;
        for (int j = 0; j < annotCount; j++)
        {
            annotname = gdpicturePDF.GetAnnotationName(j);
            if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
            {
                if (annotname.Equals("required_annotation_name"))
                    status = gdpicturePDF.SetAnnotationOpacity(j, 0);
                if (status != GdPictureStatus.OK) break;
            }
            else
                //The annotation name attribut is optional.
                if (gdpicturePDF.GetStat() != GdPictureStatus.PropertyNotFound) break;
        }
        if ((gdpicturePDF.GetStat() != GdPictureStatus.OK) &&
            (gdpicturePDF.GetStat() != GdPictureStatus.PropertyNotFound))
            break;
    }
    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
    {
        status = gdpicturePDF.SaveToFile("test_annotnames.pdf");
        if (status == 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 can't be saved. Status: " + status.ToString(), caption);
    }
    else
        MessageBox.Show("The example has failed. Status: " + gdpicturePDF.GetStat().ToString(), caption);
}
else
    MessageBox.Show("The file can't be loaded. Status: " + status.ToString(), caption);
gdpicturePDF.Dispose();
See Also