I can see there are a lot of questions for getting the number of pages in a a pdf with C, PHP and others but am wondering with a batch file or cmd is there a simple way of getti
QPDF is a lightweight alternative to PDFtk (requiring Java runtime) and pdfinfo (quite a dumb tool).
qpdf --show-npages file.pdf
It prints just the number of pages, needing no post-processing.
Packages for most Linux distributions exist, usually named just qpdf
. Pages like Softpedia host binaries for Windows. The source code can be downloaded from SourceForge, or from the official GitHub repository.
The --show-npages
option was added in a version after 4.1.0, in commit 91367239fd55f7c4996ed6158405ea10573ae3cb. To be compatible with version 4.1.0 and earlier, you can dump basic information about each page and count the pages. In Linux and OS X:
qpdf --show-pages file.pdf | grep -c ^page
On Windows, you should use findstr
and find
instead:
qpdf --show-pages file.pdf | findstr ^page | find /c /v ""