GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / GetPageCount Method
Example





In This Topic
GetPageCount Method (GdPicturePDF)
In This Topic
Returns the number of pages in the currently loaded PDF document.
Syntax
'Declaration
 
Public Function GetPageCount() As Integer
public int GetPageCount()
public function GetPageCount(): Integer; 
public function GetPageCount() : int;
public: int GetPageCount(); 
public:
int GetPageCount(); 

Return Value

The number of pages in the PDF document. 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.

Example
How to find out the number of pages in the PDF document.
Using gdpicturePDF As New GdPicturePDF()
    If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
        Dim count As Integer = gdpicturePDF.GetPageCount()
        Dim status As GdPictureStatus = gdpicturePDF.GetStat()
        If status = GdPictureStatus.OK Then
            MessageBox.Show("This PDF document contains " + count + " pages.", "Example: GetPageCount")
        Else
            MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), "Example: GetPageCount")
        End If
    Else
        MessageBox.Show("The file can't be loaded.", "Example: GetPageCount")
    End If
End Using
using (GdPicturePDF gdpicturePDF = new GdPicturePDF())
{
    if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
    {
        int count = gdpicturePDF.GetPageCount();
        GdPictureStatus status = gdpicturePDF.GetStat();
        if (status == GdPictureStatus.OK)
            MessageBox.Show("This PDF document contains " + count + " pages.", "Example: GetPageCount");
        else
            MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), "Example: GetPageCount");
    }
    else
        MessageBox.Show("The file can't be loaded.", "Example: GetPageCount");
}
See Also