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





In This Topic
SetAnnotationName Method (GdPicturePDF)
In This Topic
Sets 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 SetAnnotationName( _
   ByVal AnnotationIdx As Integer, _
   ByVal Name As String _
) As GdPictureStatus
public GdPictureStatus SetAnnotationName( 
   int AnnotationIdx,
   string Name
)
public function SetAnnotationName( 
    AnnotationIdx: Integer;
    Name: String
): GdPictureStatus; 
public function SetAnnotationName( 
   AnnotationIdx : int,
   Name : String
) : GdPictureStatus;
public: GdPictureStatus SetAnnotationName( 
   int AnnotationIdx,
   string* Name
) 
public:
GdPictureStatus SetAnnotationName( 
   int AnnotationIdx,
   String^ Name
) 

Parameters

AnnotationIdx
The 0-based index of the required annotation within the current page. It must be a value from 0 to GetAnnotationCount-1.
Name
The new annotation name of the specified annotation object.

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.

Likewise always ensure that you have selected the correct page using the 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 set the annotation name for all sticky notes in the loaded PDF document.
Dim caption As String = "Example: SetAnnotationName"
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("test.pdf", False)
If status = GdPictureStatus.OK Then
    Dim annotCount As Integer = 0
    Dim annotType As String = "", annotSubType As String = ""
    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
            annotType = gdpicturePDF.GetAnnotationType(j)
            If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then Exit For
            annotSubType = gdpicturePDF.GetAnnotationSubType(j)
            If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then Exit For
            If annotType.Equals("Annot") AndAlso annotSubType.Equals("Text") Then
                If gdpicturePDF.SetAnnotationName(j, "Text_p" + i.ToString() + "_idx" + j.ToString()) <> GdPictureStatus.OK Then Exit For
            End If
        Next
        If gdpicturePDF.GetStat() <> GdPictureStatus.OK 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: SetAnnotationName";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.LoadFromFile("test.pdf", false);
if (status == GdPictureStatus.OK)
{
    int annotCount = 0;
    string annotType = "", annotSubType = "";
    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++)
        {
            annotType = gdpicturePDF.GetAnnotationType(j);
            if (gdpicturePDF.GetStat() != GdPictureStatus.OK) break;
            annotSubType = gdpicturePDF.GetAnnotationSubType(j);
            if (gdpicturePDF.GetStat() != GdPictureStatus.OK) break;
            if (annotType.Equals("Annot") && annotSubType.Equals("Text"))
            {
                if (gdpicturePDF.SetAnnotationName(j, "Text_p" + i.ToString() + "_idx" + j.ToString()) != GdPictureStatus.OK) break;
            }
        }
        if (gdpicturePDF.GetStat() != GdPictureStatus.OK) 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