Skip to content

Instantly share code, notes, and snippets.

@enkore
Created June 23, 2012 13:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enkore/2978342 to your computer and use it in GitHub Desktop.
Save enkore/2978342 to your computer and use it in GitHub Desktop.
Simple footer with reportlab
# I place this in the public domain
def make_pdf_from_elements(elements, title, author):
# elements is a list containing flowables, while title and author are simply strings added to PDF metadata
def drawPage(canvas, doc):
canvas.setTitle(title)
canvas.setSubject(title)
canvas.setAuthor(author)
canvas.setCreator(author)
footer = []
# Put some flowables into the footer
Frame(2*cm, 0, 17*cm, 4*cm).addFromList(footer, canvas)
# Create PDF & output
buff = StringIO.StringIO()
# Note the bigger bottom margin here, which reserves some spaces for our footer
doc = SimpleDocTemplate(buff, pagesize=A4, rightMargin=2*cm, leftMargin=2*cm, topMargin=2*cm, bottomMargin=6*cm)
doc.build(elements, onFirstPage=drawPage, onLaterPages=drawPage)
return buff
@jslvtr
Copy link

jslvtr commented Jul 31, 2013

Thank you, very useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment