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 getting the number of pages?
相关问题
- Correctly parse PDF paragraphs with Python
- Set BaseUrl of an existing Pdf Document
- xcopy include folder
- Batch file if string starts by
- Jenkins - cmd is not recognized
相关文章
- 在vscode如何用code runner打开独立的控制台窗口,以及设置好调试模式时窗口的编码?
- Python Sendgrid send email with PDF attachment fil
- Extracting columns from text file using Perl one-l
- C# MVC website PDF file in stored in byte array, d
- How can one batch file get the exit code of anothe
- Command line escaping single quote for PowerShell
- How To Programmatically Enable/Disable 'Displa
- How to reduce PDF file size programmatically in Ja
It might be helpful for new users. In the new version of PDFtk tool (above 2.0), use below command to get the number of pages of a PDF file:
A new file will created at destination having content similar to below:
Now read the file and manipulate the content as you want.
Because you asked for a "batch file" I have to assume you only want a Windows-based solution. But, just in case Mac OS X is an option, here something that could be useful. If you have the PDFs on a Mac, on a drive that has been indexed by Spotlight (the default), the following command will return the number of pages using no external dependencies:
Source: MacScripter.net - http://macscripter.net/viewtopic.php?id=32381
Without any external tools (save the script bellow as
.bat
) :It takes the path to the
.pdf
file and simply prints the number of the pages.Not pretty fast as it reads the pdf symbol by symbol , but could be optimized.Using pdftk:
pdftk my.pdf dump_data | grep NumberOfPages
does the trick.
Alternatively you can use the command, which returns only the number:
pdfinfo "${PDFFILE}" | grep Pages | sed 's/[^0-9]*//'
You will need the xpdf package (usually preinstalled in many distributions):
http://www.foolabs.com/xpdf/download.html
QPDF is a lightweight alternative to PDFtk (requiring Java runtime) and pdfinfo (quite a dumb tool).
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:On Windows, you should use
findstr
andfind
instead: