Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reportlab platypus - disable table splitting

I'm making a dynamically generated report in python using Reportlab's Platypus.

I have multiple tables that are generated, most only have between 10 and 20 rows. Right now they are being automatically being split at the end of my page, but I would much rather have them stay together on the same page.

I have tried setting splitByRow to False upon Table instantiation, but that raises a "Not Implemented" error.

Also, I am not allowed make any changes to the reportLab python files, although I can see the code. Maybe I can subclass Table and disable split somehow?

What's the easiest way to disable flowable splitting?

like image 299
user1287170 Avatar asked Jul 10 '12 23:07

user1287170


1 Answers

I found the answer on my own. I import KeepTogether from reportlab.platypus.flowables and then when I add a table to the elements list, I use KeepTogether, like so:

from reportlab.platypus.flowables import KeepTogether 
t = Table(tableData)
self.elements[name] = KeepTogether(t)
like image 53
user1287170 Avatar answered Sep 23 '22 09:09

user1287170