How to get number of pages in PDF file by Adobe Acrobat 9 Pro Extended product?

Another article about how to read the page number from PDF file directly, without depend on “Adobe Acrobat 9 Pro Extended” product,

The following solution is depend on Adobe Acrobat product, the Free Adobe Reader is not enough.

Recently I faced with a question:

How to get number of pages in PDF file?

In other words, how to get number of pages for any given PDF file, like on this PDF file:
This is a VeryPDF Test File. It contains 54 pages,


Let's see how we can get this number from Adobe Acrobat Professional OLE Interface.

I created the following simple VBScript for Adobe Acrobat 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 =

        GetNumPagesInPDF = -1
    End If
End Function

I call GetNumPagesInPDF function with a full path of PDF file:

numPages = GetNumPagesInPDF("D:\VeryPDF.pdf")
MsgBox "Number of pages: " & numPages

And the result of this script is:


As you can see, this script works correctly and extracts the number of pages in PDF file.

We use Acrobat OLE object - "AcroExch.PDDoc":

Set oPDFDoc = CreateObject( "AcroExch.PDDoc" )

It provides an interface for common Acrobat document operations, such as: opening/closing, working with pages etc.

To use "AcroExch.PDDoc" object, you have to install Adobe Acrobat (do not confuse with Acrobat Reader!) on your computer.

You can check whether "AcroExch.PDDoc" object is available on your computer. For that, open a registry and check the path:


If "AcroExch.PDDoc" key exists, then you can use Acrobat OLE Automation in your scripts. If not, then Adobe Acrobat should be installed.

Important note:
Just save the code into vbs-file and run. It will return the same result - number of pages in PDF file.

If you haven’t Adobe Acrobat 9 Pro Extended product installed, please look at following web pages,

VN:F [1.9.20_1166]
Rating: 1.0/10 (1 vote cast)
VN:F [1.9.20_1166]
Rating: -1 (from 3 votes)
How to get number of pages in PDF file by Adobe Acrobat 9 Pro Extended product?, 1.0 out of 10 based on 1 rating

Related Posts

This entry was posted in Advanced PDF Tools, Spool File Page Counter SDK, VeryPDF Blog and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Verify Code   If you cannot see the CheckCode image,please refresh the page again!