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:
' 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 =
Else
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:
HKEY_CLASSES_ROOT\AcroExch.PDDoc
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,
https://www.verypdf.com/wordpress/201210/pdf-file-page-counter-32507.html
https://www.verypdf.com/pdfinfoeditor/pdf-page-numberer.html
https://www.verypdf.com/wordpress/201205/how-to-count-the-number-of-pdf-pages-in-a-folder-27465.html
https://www.verypdf.com/wordpress/201107/detect-color-pages-or-bw-pages-in-pdf-1396.html
https://www.verypdf.com/tifftoolkit/tiff-page-counter.html