Search code examples
pythondjangoreportlab

Python and ReportLab: add a string at the end of every page


I'm building a pdf document with reportlab, using the Paragraph class:

doc = SimpleDocTemplate(response, leftMargin=lateral_margin, rightMargin=lateral_margin,
    topMargin=top_bottom_margin, bottomMargin=top_bottom_margin)
Document = []
Document.append(Paragraph("bla bla bla bla", my_style))
doc.build(Document)  

Now I want to add at the end of every page a string, how can I do that??


Solution

  • Your build call can include onFirstPage and onLaterPages arguments, which are functions invoked when the page starts. You can draw on the canvas in those functions to create fixed-position elements on each page, like page headers and footers.