问题描述
我正在尝试制作一个简单的报表,该报表的中间有一个页眉/页脚和一个表,其中有很多行。
我是ReportLab的新手,而我从WeasyPrint切换的原因是我希望引擎能够很好地处理分页符。
下面是我的代码:
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,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)
页眉/页脚显示正常,表也显示良好,但是当我们转到第二页时,表将覆盖页眉。
我尝试使用KeepInFrame
添加一个框架,因为表格变得很小,无法容纳在一页的框架中。
这似乎是一个简单的任务,但是我找不到一种简单地考虑所有页面上的标题的方法。 (或者也许我采用了错误的方法?)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)