How to count pages in multiple PDF files on Windows

I needed to know the total number of pages in hundreds of PDFs. Thanks to cpdf - Coherent PDF Command Line Tools I was able to get this done from the Windows Command Prompt on Windows 8.1. Here’s the command I used,

> forfiles /s /m *.pdf /c "cmd /c C:\Users\Admin\Documents\cpdf\cpdf.exe -pages @path >> C:\Users\Admin\Documents\pages.txt && echo. >> C:\Users\Admin\Documents\pages.txt" 

This populates pages.txt with number of pages in each PDF it comes across in the directory (and sub-directories) it has been run in. You can then paste pages.txt into any spreadsheet to calculate the sum of the series.

How it works,

  1. This tells you the number of pages in a PDF file
> cpdf.exe -pages sample-pdf-file.pdf 
> forfiles /s /m *.pdf /c "cmd /c echo @file" # `/s` flag tells it to look into sub-directories. # `/m *.pdf` searches only PDF files. # `/c "cmd /c echo @file"` tells it to run `echo @file` command in cmd. 

Categories: tutorial

Created: September 30, 2019

Leave a comment

You may also enjoy

Cycling and Hiking Weekend at Udaipur

written in August, 2021. This is a 2 minute read

about: cycling, hiking, udaipur

UPI Scammer Accidentally Ends Up Giving Me 💸

written in March, 2020. This is a 2 minute read

about: payments, infosec

Playback Analysis of Boomerang Videos

written in January, 2020. This is a less than 1 minute read

Some less known Cycling Routes Around Udaipur

written in January, 2020. This is a 2 minute read

about: cycling, udaipur