带有reportLab的两列和页脚

问题描述 投票:1回答:1

我正在尝试生成具有两列和页脚的文档。当前,我将文档分为两列,但是,当我尝试在页脚中创建段落时,它会按照该列的模式排列(如果可以的话)。它实际上并没有创建页脚。我是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)
python reportlab
1个回答
0
投票

可以通过“ 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

© www.soinside.com 2019 - 2024. All rights reserved.