Shell command to count pages in a PDF (other than pdftk)?

Yet another exiftool solution:

cd /path/to/pdf/directory
exiftool -T -filename -PageCount -s3 -ext pdf .

You should be able to use mdls to view the metadata attributes for a PDF:

mdls -n kMDItemNumberOfPages "$i" | cut -c24-


You can use qpdf command line utility to count the number of pages in a PDF document. qpdf can be installed via Homebrew via running the following command:

brew install qpdf

Once installed, to count the number of pages execute:

qpdf --show-npages file.pdf


Whether the file is indexed or not this works however if the target file does not resides on a volume/location that's being indexed then here is an alternative to the excellent solution presented by jordanmerrick.

I just tried this using exiftool and if it's just the page count you want as a number then this works:

exiftool "$i" | awk -F": " '/Page Count/{print $2}'