How to mix static positioning and flowables
Mike Driscoll <[email protected]>
| Newsgroups | gmane.comp.python.reportlab.user |
|---|---|
| Message-ID | <CAO4gEAvcU9PefMNc9Y_tsB7wWQjhm56NgvkTOp_BNmRLf49akg@mail.gmail.com> |
Hi, I have a project where I'm basically creating a document where the top half has to be positioned exactly and the second half is a table that can run multiple pages. I was doing the static part using Reportlab's canvas object, but I can't figure out how to make the table split across multiple pages if it gets too long. All the resources I've found so far recommend using a Template like BaseDocTemplate, but I don't see any way to use that to mix the static content and the dynamic content on one page. I have attached what I've come up with so far, but the table obviously doesn't split. Any help would be appreciated. Thanks! ------------------- Mike Driscoll Blog: http://blog.pythonlibrary.org
multipage_test.py
(application/octet-stream, 1.8 KB)
from reportlab.graphics.barcode import code39
from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch, mm
from reportlab.pdfgen import canvas
from reportlab.platypus import Paragraph, Table, TableStyle, SimpleDocTemplate
########################################################################
class Test(object):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
self.c = canvas.Canvas("test.pdf", pagesize=letter)
self.width, self.height = letter
self.styles = getSampleStyleSheet()
#----------------------------------------------------------------------
def createDocument(self):
"""
Create the document
"""
normal = self.styles["Normal"]
address = """<font size="9">
%s<br/>
%s<br/>
%s</font>
""" % ("John Doe", "111 Hardy Ave", "Dallas, TX, 75044")
p = Paragraph(address, style=normal)
p.wrapOn(self.c, self.width, self.height)
p.drawOn(self.c, 30, 700)
# create a big piece of data
data = []
row_data = []
for row in range(100):
for col in "ABCDEF":
row_data.append(col)
data.append(row_data)
row_data = []
print
table = Table(data, colWidths=4*mm)
table.wrapOn(self.c, self.width, self.height)
table.drawOn(self.c, 18, 0)
#----------------------------------------------------------------------
def savePDF(self):
"""
Save the PDF
"""
self.c.save()
if __name__ == "__main__":
t = Test()
t.createDocument()
t.savePDF()