How to get number of pages in PDF file?

Posted on Aug 10 2009 - 11:31am by Raj

I created the following simple VBScript for QuickTest Professional to extract number of pages in PDF file:

‘ Function GetNumPagesInPDF returns the number of pages in PDF file

‘ FileName – path to given ODF file

‘ If a file isn’t found, then -1 will be returned

Function GetNumPagesInPDF(FileName)

    Dim oPDFDoc

    Set oPDFDoc = CreateObject( “AcroExch.PDDoc” )


    If oPDFDoc.Open( FileName ) Then

        GetNumPagesInPDF = oPDFDoc.GetNumPages()

        Set oPDFDoc = Nothing


        GetNumPagesInPDF = -1

    End If

End Function

About the Author

Leave A Response