#!/bin/python # Assemble a collection of PNG files (which may also # actually be JPEG files) into a PDF file. # Before this will run (as of Fedora 17), you must: # yum install python-reportlab # yum install python-reportlab-docs (a good idea). # yum install python-imaging (important and vital) import os try: from reportlab.lib import pagesizes from reportlab.pdfgen import canvas from reportlab.lib.units import cm, mm, inch, pica except ImportError: print ( "You need to install the python-reportlab package" ) exit () images = [] for f in os.listdir("."): if f.endswith(".png"): images.append ( f ) images.sort() for f in images : print f pagesize=pagesizes.A4 margin=1*cm page_width, page_height = pagesize width = page_width - 2 * margin height = page_height - 2 * margin c = canvas.Canvas( "out.pdf", pagesize=pagesize) for image_path in images: c.drawImage(image_path, margin, margin, width, height) c.showPage() c.save() # THE END