提问人:thiago tavares 提问时间:11/7/2023 更新时间:11/7/2023 访问量:17
ReportLab 的页眉和页脚
header and footer with reportlab
问:
我的代码有问题:
from reportlab.platypus import SimpleDocTemplate, PageTemplate, Frame, Paragraph, PageBreak
from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import getSampleStyleSheet
def header(canvas, doc):
canvas.saveState()
canvas.setFont('Helvetica', 12)
canvas.drawString(36, letter[1] - 36, "CABEÇA")
canvas.restoreState()
def footer(canvas, doc):
canvas.saveState()
canvas.setFont('Helvetica', 12)
canvas.drawString(36, 36, "PÉZÃO")
canvas.restoreState()
pdf_filename = "exemplo.pdf"
doc = SimpleDocTemplate(pdf_filename, pagesize=letter)
styles = getSampleStyleSheet()
normal_style = styles["Normal"]
frame = Frame(36, 36, letter[0] - 72, letter[1] - 72)
template = PageTemplate(id='page_with_header_footer', frames=frame, onPage=header, onPageEnd=footer)
doc.addPageTemplates([template])
story = []
for i in range(10):
story.append(Paragraph(f"Conteúdo da Página {i + 1}", normal_style))
story.append(PageBreak())
story.pop()
doc.build(story)
我正在尝试使用 reportlab 生成一个文档,其中所有页面都带有页眉和页脚,但是,只有我的第一页带有页眉和页脚。我不知道还能做什么:C
答: 暂无答案
评论