简体   繁体   中英

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

I'm using the open source version Reportlab with Python on Windows. My code loops through multiple PNG files & combines them to form a single PDF. Each PNG is stretched to the full LETTER spec (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. Is there something that I need to add between each drawImage() to offset to a new page? 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. ( 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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