How can I output the number of pages in a PDF in the Terminal? I looked into the lp
family of commands, with no luck however.
-
What are you really looking for? In other words, are you just looking for a numeric value as the only output?– user3439894Commented Jan 27, 2016 at 13:14
Add a comment
|
2 Answers
Using Apple's mdls
:
mdls -name kMDItemNumberOfPages file.pdf
to get just the number of pages:
mdls -name kMDItemNumberOfPages -raw file.pdf
You can use pdf command line tools (xpdf) from foolabs.com
There's pdfinfo
which outputs something like this:
Tagged: no
Form: none
Pages: 4
Encrypted: no
Page size: 612 x 792 pts (letter) (rotated 0 degrees)
File size: 134885 bytes
Optimized: yes
PDF version: 1.4
So You can get number of pages with:
pdfinfo /path/to/file.pdf | grep Pages