[reportlab-users] Page Breaks with Paragraphs

Tim Johnson reportlab-users@reportlab.com
Tue, 26 Oct 2004 17:11:33 -0800


Hello List:
    I'm using code from one of the examples:
the following loop:
def go():
    doc = SimpleDocTemplate("phello.pdf")
    Story = [Spacer(1,0.2*inch)]
    style = styles["Normal"]
    for i in range(100):
        bogustext = ("<font color=\"red\">This</font> is Paragraph number %s.  " % i) * 8
        p = Paragraph(bogustext, style)
        Story.append(p)
        Story.append(Spacer(1, 0.2 * inch))
    doc.build(Story, onFirstPage = myFirstPage, onLaterPages = myLaterPages)
## builds a pdf file properly, but I would like to find a strategy to
## introduce "page breaks" so that paragraphs do not span pages.
## I would welcome examples, instructions or pointers to such..
Thanks
tim
---
callback function code follows:
def myFirstPage(canvas, doc):
    canvas.saveState()
    canvas.setFont('Times-Bold',14)
    canvas.drawCentredString(PAGE_WIDTH/2.0, PAGE_HEIGHT - 24, Title)
    canvas.setFont('Times-Roman',9)
    canvas.drawString(inch, 0.75 * inch, "First Page / %s" % pageinfo)
    canvas.restoreState()
def myLaterPages(canvas, doc):
    canvas.saveState()
    canvas.setFont('Times-Roman',9)
    canvas.drawString(inch, 0.75 * inch, "Page %d %s" % (doc.page, pageinfo))
    canvas.restoreState()

-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com