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:
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.
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,