Python: how to get Reportlab to go to the next page in PDF format

I am using the open source version of Reportlab with Python on Windows. My code goes through several PNG files and combines them to form a single PDF file. Each PNG is stretched to the full LETTER specification (8.5x11).

The problem is that all the images stored in output.pdf are clamped on top of each other, and only the last added image is visible. Is there something I need to add between each drawImage() to offset to a new page? Here is a simple linear look at 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() 
+6
source share
1 answer

[Subsequent comment to the post]

Use canv.showPage() after using canv.drawImage(...) every time. ( http://www.reportlab.com/apis/reportlab/dev/pdfgen.html#reportlab.pdfgen.canvas.Canvas.showPage )

Follow the source document (in this case, any tool that you use, you must insert the appropriate documentation on the site into it): http://www.reportlab.com/apis/reportlab/dev/pdfgen.html

+8
source

Source: https://habr.com/ru/post/910660/


All Articles