Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to group objects in reportlab, so that they stay together across new pages

I'm generating some pdf files using reportlab. I have a certain section that is repeated. It contains of a header and a table:

            Story.append(Paragraph(header_string, styleH))
            Story.append(table) 

How can I group the paragraph with the table (in latex I would put them into the same environment) so that in case of a page brake, the paragraph and table stay together? Currently the paragraph sometimes floats at the end of one page and the table starts on top of the next page.

like image 954
memyself Avatar asked Jan 25 '11 18:01

memyself


People also ask

What is Reportlab?

ReportLab is a free open-source document creation engine for generating PDF documents and custom vector graphics. It has been available in a free open-source version since 2000; however, the company also offers a commercial version of the product called ReportLab PLUS.


1 Answers

this is the solution that I found going through the reportlab source code:

paragraph = Paragraph(header_string, styleH)
paragraph.keepWithNext = True
Story.append(paragraph)
Story.append(table)
like image 129
memyself Avatar answered Sep 18 '22 07:09

memyself