The script assumes that each subfolder in the current (or specified) path contains a collection of images that should be converted into a single PDF. It also assumes that the images are named in such a way that sorting by filename will place the pages in the correct order. For each subfolder, a similarly named PDF is created in the main folder.
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4
import os, sys, glob
width, height = A4
if len(sys.argv) > 1:
os.chdir(sys.argv) # Change working directory
print "Usage: pics2pdf [directory]"
# Iterate over all the subdirectories of the current directory:
for subdir in filter(os.path.isdir, os.listdir('.')):
pdfname = subdir+".pdf"
ignorelist = 
print "Processing", pdfname, "[",
c = canvas.Canvas(pdfname)
# Iterate over all the possible pictures in the subdirectory:
PicList = glob.glob(os.path.join(subdir,"*"))
for pic in PicList:
try: # Assume the file is a valid image
c.drawImage(pic, 0, 0, width, height)
except: # Didn't seem to be an image
if len(ignorelist) > 0:
print "Ignored non-image file(s)",
for file in ignorelist: