Reputation: 7031
I'm trying to make a simple report that has a header/footer and table in the middle with a ot of rows.
I'm new to ReportLab and the reason I switched from WeasyPrint is because I wanted the engine to handle page breaks nicely.
Below is my code :
def print_users(self):
buffer = self.buffer
doc = BaseDocTemplate(buffer,
rightMargin=20,
leftMargin=20,
topMargin=20,
bottomMargin=20,
pagesize=landscape(self.pagesize))
frame = Frame(
doc.leftMargin,
doc.bottomMargin,
doc.width,
doc.height - inch * 0.5,
id='normal',
showBoundary=1)
template = PageTemplate(id='all_pages', frames=frame, onPage=self._header_footer)
doc.addPageTemplates([template])
styles=getSampleStyleSheet()
# Our container for 'Flowable' objects
elements = []
elements.append(Spacer(1, 3*units.cm))
title = self.event.name
elements.append(Paragraph(self.event.name, styles["Normal"]))
elements.append(Spacer(1, 1*units.cm))
data = []
titles = ['First name', 'Last name', 'Position', 'Institution']
data.append(titles)
for invitation in self.invitations:
line = []
line.append(invitation.person.firstname)
line.append(invitation.person.lastname)
line.append(invitation.person.position)
line.append(invitation.institution.name)
data.append(line)
t=Table(data)
t.setStyle(TableStyle(
[('LINEBELOW',(0,0),(-1,-1),1, colors.gray)]))
table_story = [t]
elements.append(t)
# t_keep = KeepInFrame(0, 0, table_story, hAlign='CENTER', vAlign='MIDDLE', fakeWidth=False)
# write the document to disk
# Draw things on the PDF. Here's where the PDF generation happens.
# See the ReportLab documentation for the full list of functionality.
# elements.append(t_keep)
doc.build(elements)
The header/footer are showing fine and so is the table , but when we go to the second page, the table overrides the header.
I tried to add a frame with KeepInFrame
ut the table becomes so small to fit inside the frame in one page.
It seems like a simple task, but i can't find a way to simply take into consideration the header on all pages. (Or maybe i'm taking the wrong approach?)
Upvotes: 2
Views: 1354
Reputation: 11
I face the same issue but in my case was because my header take like 20 mm of space meanwhile my topMargin was only 10mm. Changing the topMargin to more than 20 fix the issue.
Upvotes: 1