Example





In This Topic
GdPicture14 Namespace / GdPicturePDF Class / GetAnnotationCount Method

GetAnnotationCount Method (GdPicturePDF)

In This Topic
Returns the number of all annotation objects contained within the currently selected page of the loaded PDF document.

The standard annotation types are described in the PDF Reference, Section "Annotation Types". You can subsequently use the GetAnnotationSubType method to find out the correct subtype ("Popup", "Text", "FreeText", etc.) of the specific annotation object.

Please note that the final count of all annotation objects on the current page also includes all those Popup annotation objects, that are expressly detected in the internal structure of the currently loaded PDF document.

Syntax
'Declaration
 
Public Function GetAnnotationCount() As Integer
public int GetAnnotationCount()
public function GetAnnotationCount(): Integer; 
public function GetAnnotationCount() : int;
public: int GetAnnotationCount(); 
public:
int GetAnnotationCount(); 

Return Value

The number of all annotation objects on the current page, that includes Popup annotation objects (expressly inscribed in the document's internal structure) as well. 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.

You also need to be aware that the final count of all annotations on the page also includes all Popup annotations as well. You can use the GetAnnotationSubType method to determine the subtype ("Popup", "Text", "FreeText", etc.) of the specific annotation object.

Example
How to find out the number of all annotation objects within the current page of the PDF document.
Dim caption As String = "Example: GetAnnotationCount"
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 annots As Integer = 0
    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 SelectPage(" + i.ToString() + ") method has failed with the status: " + status.ToString() + vbCrLf
        Else
            message = message + "The page nr." + i.ToString()
            Dim annotCount As Integer = gdpicturePDF.GetAnnotationCount()
            status = gdpicturePDF.GetStat()
            If status <> GdPictureStatus.OK Then
                message = message + ": the GetAnnotationCount() method has failed with the status: " + status.ToString() + vbCrLf
            Else
                If annotCount = 0 Then
                    message = message + " does not contain any annotations." + vbCrLf
                Else
                    message = message + " contains " + annotCount.ToString() + " annotations." + vbCrLf
                    annots = annots + annotCount
                End If
            End If
        End If
    Next
    message = message + "The total number of annotations in this document is: " + annots.ToString()
    MessageBox.Show(message, caption)
Else
    MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: GetAnnotationCount";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.LoadFromFile("test.pdf", false);
if (status == GdPictureStatus.OK)
{
    string message = "";
    int annots = 0;
    int pageCount = gdpicturePDF.GetPageCount();
    for (int i = 1; i <= pageCount; i++)
    {
        status = gdpicturePDF.SelectPage(i);
        if (status != GdPictureStatus.OK)
        {
            message = message + "The SelectPage(" + i.ToString() + ") method has failed with the status: " + status.ToString() + "\n";
        }
        else
        {
            message = message + "The page nr." + i.ToString();
            int annotCount = gdpicturePDF.GetAnnotationCount();
            status = gdpicturePDF.GetStat();
            if (status != GdPictureStatus.OK)
            {
                message = message + ": the GetAnnotationCount() method has failed with the status: " + status.ToString() + "\n";
            }
            else
            {
                if (annotCount == 0)
                {
                    message = message + " does not contain any annotations." + "\n";
                }
                else
                {
                    message = message + " contains " + annotCount.ToString() + " annotations." + "\n";
                    annots = annots + annotCount;
                }
            }
        }
    }
    message = message + "The total number of annotations in this document is: " + annots.ToString();
    MessageBox.Show(message, caption);
}
else
{
    MessageBox.Show("The file can't be loaded.", caption);
}
gdpicturePDF.Dispose();
See Also