Answer the question
In order to leave comments, you need to log in
How to count the number of pages of multiple PDF files?
Actually the question is how in the windows environment to calculate the total number of pages of many pdf-files in a directory? Preferably without installing any software, or it should be portable ...
Answer the question
In order to leave comments, you need to log in
Either use the appropriate assembly to work with the pdf, or use the trickier .
You can take any open source PDF library and write the application yourself. It's not hard.
Here is a python solution compiled with py2exe into an exe file and does not require .net (uses pyPdf if you run the script itself). The first parameter is the path to the folder, and if it is not present, then it is considered that this is the current directory:
# -*- coding: utf-8 -*-
import os
import sys
from pyPdf import PdfFileReader
PDF_EXTENSION = '.pdf'
DEFAULT_PATH = '.'
def pages_count(path):
return PdfFileReader(file(path, "rb")).getNumPages()
if __name__=="__main__":
path = sys.argv[1] if len(sys.argv) > 1 else DEFAULT_PATH
total_pages_count = 0
for root, dirs, files in os.walk(path):
for file_name in files:
if file_name[-len(PDF_EXTENSION):] == PDF_EXTENSION:
file_path = os.path.join(root, file_name)
file_pages_count = pages_count(file_path)
print file_path, file_pages_count
total_pages_count += file_pages_count
print 'total:', total_pages_count
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question