Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()                                                      
like image 929
user1145643 Avatar asked Mar 14 '12 05:03

user1145643


1 Answers

[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

like image 83
Harshith J.V. Avatar answered Sep 27 '22 19:09

Harshith J.V.