gpt4 book ai didi

python - Reportlab 第 x 页,共 y 页 NumberedCanvas 和图像

转载 作者:太空狗 更新时间:2023-10-30 01:49:49 25 4
gpt4 key购买 nike

我一直在使用 http://code.activestate.com/recipes/546511/ 提供的报告实验室 NumberedCanvas .但是,当我尝试构建包含图像流动对象的 PDF 时,图像不显示,尽管为图像留出了足够的垂直空间。有解决办法吗?

最佳答案

参见 my new, improved recipe为此,其中包括一个简单的图像测试。这是食谱的摘录(省略了测试代码):

from reportlab.pdfgen import canvas
from reportlab.lib.units import mm

class NumberedCanvas(canvas.Canvas):
def __init__(self, *args, **kwargs):
canvas.Canvas.__init__(self, *args, **kwargs)
self._saved_page_states = []

def showPage(self):
self._saved_page_states.append(dict(self.__dict__))
self._startPage()

def save(self):
"""add page info to each page (page x of y)"""
num_pages = len(self._saved_page_states)
for state in self._saved_page_states:
self.__dict__.update(state)
self.draw_page_number(num_pages)
canvas.Canvas.showPage(self)
canvas.Canvas.save(self)

def draw_page_number(self, page_count):
self.setFont("Helvetica", 7)
self.drawRightString(200*mm, 20*mm,
"Page %d of %d" % (self._pageNumber, page_count))

关于python - Reportlab 第 x 页,共 y 页 NumberedCanvas 和图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1087495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com