Making a PDF from GIF pictures • 5 Feb 2008

Somebody asked me if I knew an easy way to make a bunch of scanned pictures (GIF, JPG etc) into a PDF file. Actually this is very easy using the ReportLab toolkit. I installed it from the Python package index: http://pypi.python.org/pypi/reportlab/2.4, but you can also use 'pip', for instructions see PyPI.

The script is surprisingly simple. It just creates a new ReportLab canvas, and adds a page for each picture it finds in the current directory. The page size gets adjusted to the picture size, so the pictures don't necessarily all have to be the same size.

from reportlab.pdfgen import canvas import glob c = canvas.Canvas("book.pdf") for fn in glob.glob("*.gif"): dim=c.drawImage(fn,0,0) c.setPageSize(dim) c.showPage() c.save()


I scanned some doodles and combined them into a PDF.

A screenshot of the resulting PDF:.

Screenshot of resulting PDF


Leave a comment

name (required)

content last edited on January 7, 2011, 03:57 - rendered in 2.27 msec