我正在尝试生成一个包含两列和两页脚的文档。目前我将文档拆分为两列,但是当我尝试在页脚中创建段落时,它只是遵循列的模式,如果这有意义的话。它实际上并不创建页脚。我是reportLab的新手,对这个库没有很好的了解。
document = SimpleDocTemplate("test.pdf", pagesize=letter,rightMargin=72,leftMargin=72,topMargin=72,bottomMargin=18 )
#Two Columns
frame1 = Frame(document.leftMargin, document.bottomMargin, document.width/2-6, document.height, id='col1')
frame2 = Frame(document.leftMargin+document.width/2+6, document.bottomMargin, document.width/2-6, document.height, id='col2')
document.addPageTemplates([PageTemplate(id='TwoCol',frames=[frame1,frame2])])
story = []
ptext = '* Example blah blah'
story.append(Paragraph(ptext, styles["Normal"]))
ptext = '* Example blah blah'
story.append(Paragraph(ptext, styles["Normal"]))
footer = Frame(document.leftMargin, document.bottomMargin, document.width, document.height, id="footer")
document.addPageTemplates([PageTemplate(id='Footer',frames=[footer])])
ptext = '* Example blah blah'
story.append(Paragraph(ptext, styles["Normal"]))
ptext = '* Example blah blah'
story.append(Paragraph(ptext, styles["Normal"]))
document.build(story)发布于 2020-05-27 06:27:59
可以通过"onPage“在页面模板上添加页脚和页眉元素
给定您的代码行:
document.addPageTemplates([PageTemplate(id='TwoCol',frames=[frame1,frame2])])例如,您可以执行以下操作(请注意onPage的添加):
styles = getSampleStyleSheet()
styleN = styles['Normal']
def footer(canvas, doc):
canvas.saveState()
P = Paragraph("This is a multi-line footer. It goes on every page. " * 5, styleN)
w, h = P.wrap(doc.width, doc.bottomMargin)
P.drawOn(canvas, doc.leftMargin, h)
canvas.restoreState()
document.addPageTemplates([PageTemplate(id='TwoCol', onPage=footer, frames=[frame1,frame2])])在这里可以看到类似的问题:A multiline(paragraph) footer and header in reportlab
https://stackoverflow.com/questions/59778369
复制相似问题