简体   繁体   English

Python:如何使Reportlab移动到PDF输出中的下一页

[英]Python: How to make Reportlab move to next page in PDF output

I'm using the open source version Reportlab with Python on Windows. 我在Windows上使用开源版Reportlab和Python。 My code loops through multiple PNG files & combines them to form a single PDF. 我的代码循环遍历多个PNG文件并将它们组合成一个PDF。 Each PNG is stretched to the full LETTER spec (8.5x11). 每个PNG都被拉伸到完整的LETTER规范(8.5x11)。

Problem is, all the images saved to output.pdf are sandwiched on top of each other and only the last image added is visible. 问题是,保存到output.pdf的所有图像都夹在彼此的顶部,只有最后添加的图像是可见的。 Is there something that I need to add between each drawImage() to offset to a new page? 我需要在每个drawImage()之间添加一些内容以偏移到新页面吗? Here's a simple linear view of what I'm doing - 这是我正在做的简单线性视图 -

WIDTH,HEIGHT = LETTER                                            
canv = canvas.Canvas('output.pdf',pagesize=LETTER)               
canv.setPageCompression(0)                                       

page = Image.open('one.png')                                     
canv.drawImage(ImageReader(page),0,0,WIDTH,HEIGHT)

page = Image.open('two.png')                                     
canv.drawImage(ImageReader(page),0,0,WIDTH,HEIGHT)

page = Image.open('three.png')                                   
canv.drawImage(ImageReader(page),0,0,WIDTH,HEIGHT)

canv.save()                                                      

[Follow up of the post's comment] [关注帖子的评论]

Use canv.showPage() after you use canv.drawImage(...) each time. canv.showPage()使用canv.drawImage(...)后使用canv.drawImage(...) ( http://www.reportlab.com/apis/reportlab/dev/pdfgen.html#reportlab.pdfgen.canvas.Canvas.showPage ) http://www.reportlab.com/apis/reportlab/dev/pdfgen.html#reportlab.pdfgen.canvas.Canvas.showPage

Follow the source document(for that matter any tool you are using, you should dig into it's respective website documentation): http://www.reportlab.com/apis/reportlab/dev/pdfgen.html 关注源文档(对于您正在使用的任何工具,您应该深入了解它的相应网站文档): http//www.reportlab.com/apis/reportlab/dev/pdfgen.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM