0

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.

1
  • What are you really looking for? In other words, are you just looking for a numeric value as the only output? Commented Jan 27, 2016 at 13:14

2 Answers 2

7

Using Apple's mdls:

 mdls -name kMDItemNumberOfPages file.pdf

to get just the number of pages:

 mdls -name kMDItemNumberOfPages -raw file.pdf
1
  • Built-in and does exactly what I need. Perfect.
    – fabian789
    Commented Jan 27, 2016 at 13:36
2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .