Python and PDF

Here is an example of how to merge the first pages of a number of pdf pages into a single file.

I wrote this script, because I needed to print the first page of 200 individual files and I didn’t really want to open each one manually…


import os.path, pyPdf
from os import walk
output = pyPdf.PdfFileWriter()
original = "c:\\original\\folder\\"
f = []
for (dirpath, dirnames, filenames) in walk(original): f.extend(filenames)
for eachfile in filenames: 
	ffile = original + "\\" + eachfile
	if "pdf" in eachfile:
		pdf = pyPdf.PdfFileReader(open(ffile, "rb"))
	print ffile
outputStream = open("c:\\out.pdf", "wb")