Created
June 23, 2012 13:43
-
-
Save enkore/2978342 to your computer and use it in GitHub Desktop.
Simple footer with reportlab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, very useful!