使用 ReportLab 显示页数 [英] Showing page count with ReportLab
问题描述
我正在尝试向使用 ReportLab 制作的报告添加一个简单的第 x 页".我发现 这篇关于它的旧帖子,但也许六年后出现了更直接的东西?^^;
我也找到了 这个食谱,但是当我使用它时,生成的 PDF 缺少图像..
I'm trying to add a simple "page x of y" to a report made with ReportLab.. I found this old post about it, but maybe six years later something more straightforward has emerged? ^^;
I found this recipe too, but when I use it, the resulting PDF is missing the images..
推荐答案
我能够从 ActiveState 实施 NumberedCanvas 方法.这很容易做到,并且没有改变我现有的代码.我所要做的就是在构建我的文档时添加那个 NumberedCanvas 类并添加 canvasmaker 属性.我还更改了x of y"显示位置的测量值:
I was able to implement the NumberedCanvas approach from ActiveState. It was very easy to do and did not change much of my existing code. All I had to do was add that NumberedCanvas class and add the canvasmaker attribute when building my doc. I also changed the measurements of where the "x of y" was displayed:
self.doc.build(pdf)
变成了
self.doc.build(pdf, canvasmaker=NumberedCanvas)
doc 是 BaseDocTemplate,pdf 是我的可流动元素列表.
doc is a BaseDocTemplate and pdf is my list of flowable elements.
这篇关于使用 ReportLab 显示页数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!