ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE. Software > Coding Snack Guidelines

Count Number of Pages in PDF Files

(1/3) > >>

I'd like a small program that allows me to select multiple PDF files or a directory with PDF files (recursive) and see the total number of pages across the files.

For example, if I have folder A with ten three-page PDF files and folder B with five five-page PDF files, and I select both folders, the program would display a dialog box with the total number of pages in the PDF files (55 pages).

Optionally, it would be nice to have the program output a delimited text file with the file name, file size, and number of pages, kind of like a DIR command, but with page numbers as an added property. Then I could import it into the database/spreadsheet program of my choice.

CMD or GUI would be fine.

This only gets you part way:

Command-line pdfinfo from the XPDF suite will print the page count of an individual file, amongst much other data.  So can
PDFTK, but again one file at a time.

You could put either in a batch file for multiple PDFs, but you'd have to massage the output data to make it tidy.

You could put either in a batch file for multiple PDFs, but you'd have to massage the output data to make it tidy.
--- End quote ---

I had looked into using pdfinfo before, but the output would indeed need some massaging. The source code for pdfinfo is at When I use the command pdfinfo -meta [filename], I get the following output:

--- Code: Text ---Tagged:         noForm:           nonePages:          7Encrypted:      noPage size:      613 x 790 ptsFile size:      339400 bytesOptimized:      noPDF version:    1.4
Maybe someone could create a spin-off from this so that, instead of creating a eight-line block of text, it created a single line in a delimited (maybe comma-delimited) text file with column headers in the first line—something like this:

--- Code: Text ---Tagged,Form,Pages,Encrypted,Page width,Page height,File size,Optimized,PDF Versionnone,7,no,613,790,339400,no,1.4
Then it could easily be used in a batch file operation and/or in a GUI.

Couldn't you just grep the output to find the Pages: line then use set to pull out the page count?  Set has some niceties you don't often think about.

If you're willing to add a couple of extra files, (besides pdfinfo.exe), to get it working here's a DOS batch/command file that will output:

"Filename", pages

Call as follows:

PDF-Pages.cmd <directory>

Include quotes around the directory path if required, eg. PDF-Pages.cmd "D:\My Documents"

Output goes to a file named output.txt.

--- Code: Text ---REM [email protected] offdel output.txtfor /r %1 %%f in (*.pdf) do pdfinfo.exe -meta "%%f" >out.txt & echo "%%f", | tr.exe -d "\r\n" >>output.txt & find "Pages:" out.txt | tr.exe -d "\055\056\072[:alpha:][:space:]" >>output.txt & echo. >>output.txtdel out.txt
You'll need tr.exe, libintl3.dll and libiconv2.dll from coreutils binaries and coreutils dependencies archives available here - put them in the same directory as the batch/command file.

Worked OK here over 380 PDF files in 21 sub-directories.

Anyway, it was an exercise in DOS :D

EDIT: Ooppss!  Just realised not what you're after  :-[


[0] Message Index

[#] Next page

Go to full version