Reference Guide
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. Please always use the GetStat method to determine if this method has been successful.
    Remarks
    Please note that this method is only allowed for use with non-encrypted documents.

    We strongly recommend using the GetStat method to identify the specific reason for the method's failure.

    Example
    How to find out the number of pages in the PDF document.
    Using oGdPicturePDF As New GdPicturePDF()
        If oGdPicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
            Dim count As Integer = oGdPicturePDF.GetPageCount()
            Dim status As GdPictureStatus = oGdPicturePDF.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 oGdPicturePDF = new GdPicturePDF())
    {
        if (oGdPicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
        {
            int count = oGdPicturePDF.GetPageCount();
            GdPictureStatus status = oGdPicturePDF.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