Python 3.8 x64 | Windows 10 x64 | reportlab v3.5.46 (open-source)
Been searching everywhere for an answer on this to no avail. I just want to create a PDF document that contains a lot of text. After the first page is completely full of text, the remaining text should flow onto a second page. After the second page is completely full of text, the remaining text should flow onto a third page (and so on)...
All answers I find searching around the world via the internet states to use the canvas.showPage() method. This is not a great solution because in all of these examples the first page is not completely populated with text hence it is a manual method of adding a new page. In my example I do not know when the first page will be filled with text thus I do not know when I need to create a second or new page using canvas.showPage().
I need to somehow detect when the first page cannot hold any more text, and when this occurs create a new page to hold the text which remains.
From reading over the reportlabs documentation, I am not sure how to achieve this in a practical pythonic implementation. There are also platypus.PageBreak() and BaseDocTemplate.afterPage() methods but not sure what they do because the documentation is sparse on these methods.
I don't think the code I am using will be much value for my question, but it is included below for reference. The function parameter my_text is a multi-page amount of text.
from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.pagesizes import LETTER
from reportlab.lib.units import inch
def create_pdf_report_text_object(my_text):
canvas = Canvas('Test.pdf', pagesize=LETTER)
canvas.setFont('Helvetica', size=10)
text_object = canvas.beginText(x=1 * inch, y=10 * inch)
for line in my_text.splitlines(False):
text_object.textLine(line.rstrip())
canvas.drawText(text_object)
canvas.save()