Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get number of pages in a pdf using a cmd batch file

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?

like image 968
Peter Craig Avatar asked Oct 17 '22 17:10

Peter Craig


People also ask

How do I count the number of pages in a folder?

Method 1: Check Details in File Folder Then open the file folder and click “More options” button next to “Change your view”. Next click “Details”. Now right click on the header row and choose “More”. In the “Choose Details” dialog box, check “Pages” and “Word count” boxes.


2 Answers

Using pdftk:

pdftk my.pdf dump_data | grep NumberOfPages

does the trick.

like image 80
Tuure Laurinolli Avatar answered Oct 19 '22 06:10

Tuure Laurinolli


Alternatively you can use the command, which returns only the number:

pdfinfo "${PDFFILE}" | grep Pages | sed 's/[^0-9]*//'

You will need the poppler package:

https://poppler.freedesktop.org/

Which can be installed using either homebrew / linuxbrew:

brew install poppler

or with apt:

sudo apt install poppler-utils
like image 39
dimib Avatar answered Oct 19 '22 07:10

dimib