MacOS – Get Number of PDF Pages in Terminal

macospdfterminal

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.

Best Answer

Using Apple's mdls:

 mdls -name kMDItemNumberOfPages file.pdf

to get just the number of pages:

 mdls -name kMDItemNumberOfPages -raw file.pdf