I'm trying to create and add pages manually to a PDF file, using Python 3 and reportlab.
I can easily create the first page, and draw on it. But I don't know how to manually add new pages.
Example:
from reportlab.pdfgen.canvas import Canvas
canvas = Canvas(pdf_path, pagesize=(WIDTH_OF_PAGE1,HEIGHT_OF_PAGE1))
canvas.rect(100,100,200,200,fill=1, stroke=1) # draw on the first page, this is just an example...
# Now create and add a new page here, but how???
canvas2.rect(200,200,300,300,fill=1, stroke=1) # draw on the second page, this is just an example...
# Finally, save the PDF
canvas.save()
How do I start a new page of a specific size?
Please note that I'm not using Platypus. These pages don't have a fixed height. Every page will have a different height, that is pre-calculated by some algorithm. So the concept of "flowables" cannot be used here, and I need to add pages of specific (different) sizes to a PDF document.
A workaround solution could be to create a separate PDF file for each page, then concatenate them with an external program, but I don't like that idea.