【问题标题】:add a full page image as the last page of reportlab添加整页图片作为reportlab的最后一页
【发布时间】:2012-04-25 17:00:17
【问题描述】:

我有一个使用 reportlab 生成的 pdf。我正在使用SimpleDocTemplate 渲染文档,前n 页都是相同的,但最后一个完全不同(格式和内容),由一个应该占据整个页面的图像组成。将图像添加为Flowable 元素时,出现越界错误,因为它对于定义的页面边界来说太大了。

我可以使用画布很好地渲染它,但它会出现在每个页面上 - 有没有人建议最好的方法来解决这个问题?

谢谢

【问题讨论】:

    标签: python reportlab


    【解决方案1】:

    如果您知道最后页码:

    def onLaterPages(self, doc, canvas):
        if doc.page == TOTAL_PAGES:
            canvas.saveState()
            canvas.drawImage(filename, 0, 0, *pagesize)
            canvas.restoreState()
    
    # and when calling doc.build
    doc.build(..., onLaterPages=onLaterPages)
    

    如果您不知道总页码,请查看this,但我认为他们没有使用 SimpleDocTemplate...

    【讨论】:

    • 我只是提到 *pagesize...还是应该用一个值替换它??
    • 我认为 pagesize 应该是tuple IIRC。它是(宽度,高度)。可以是常量之一。
    猜你喜欢
    • 2017-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-01
    • 1970-01-01
    • 2021-08-14
    • 2020-07-10
    相关资源
    最近更新 更多