Reputation: 293
I am using Reportlab to generate tables in a pdf format. However, I have gotten to a point where I need to include multiple tables in the same file, where some of these tables cross multiple pages. I think the tables that cross multiple pages are generating errors for me.
I used the format from this answer, to base my code on: Multiple tables (5) one one page using ReportLab
Code that produces an error:
from reportlab.lib import colors
from reportlab.lib.pagesizes import letter, inch
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle
doc = SimpleDocTemplate("test.pdf")
elements = []
data1= [['00', '01', '02', '03', '04','10', '11', '12', '13', '14'],
['10', '11', '12', '13', '14', '10', '11', '12', '13', '14'],
['20', '21', '22', '23', '24', '10', '11', '12', '13', '14'],
['30', '31', '32', '33', '34', '10', '11', '12', '13', '14']]
t1=Table(data1)
t1.setStyle(TableStyle([('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
('BOX', (0,0), (-1,-1), 0.25, colors.black),
]))
data2= [[x] for x in range(40)]
t2=Table(data2)
t2.setStyle(TableStyle([('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
('BOX', (0,0), (-1,-1), 0.25, colors.black),
]))
data = [[t1],[t2]]
overallTable = Table(data)
elements.append(overallTable)
doc.build(elements)
The error received from running:
Traceback (most recent call last):
File "", line 267, in <module>
Func1(List)
File "", line 207, in Func1
doc.build([overallTable])
File "C:\Python34\lib\site-packages\reportlab\platypus\doctemplate.py", line 1171, in build
BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker)
File "C:\Python34\lib\site-packages\reportlab\platypus\doctemplate.py", line 927, in build
self.handle_flowable(flowables)
File "C:\Python34\lib\site-packages\reportlab\platypus\doctemplate.py", line 829, in handle_flowable
raise LayoutError(ident)
reportlab.platypus.doctemplate.LayoutError: Flowable <Table@0x033F2AF0 1 rows x 4 cols(tallest row 6648)> with cell(0,0) containing
"<Table@0x03405F50 10 rows x 3 cols(tallest row 18)> with cell(0,0) containing\n'Local'"(1100.24 x 6648), tallest cell 6648.0 points, too large on page 2 in frame 'normal'(439.27559055118104 x 685.8897637795275*) of template 'Later'
I did find this solution to a similar error https://stackoverflow.com/a/27580676/4033176 but I never defined the spacers.
Is there a consistent way using Reportlab to be able to make a pdf file with multiple tables, where some are longer than a page? (other than combining pdf files)
Upvotes: 4
Views: 4253
Reputation: 20344
The problem is that you are nesting tables. This means that the long table t2
makes a single cell longer than a page - this is what is giving you the error, rather than the table being longer than a page.
Replace
data = [[t1],[t2]]
overallTable = Table(data)
elements.append(overallTable)
with
elements.append(t1)
elements.append(t2)
Upvotes: 4