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,

https://www.verypdf.com/wordpress/201307/how-to-count-pages-in-pdf-file-determine-number-of-pages-in-a-pdf-file-37621.html

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,

image

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 =
Nothing
    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:

image

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/201307/how-to-count-pages-in-pdf-file-determine-number-of-pages-in-a-pdf-file-37621.html

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

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

Related Posts

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!