I’m generating a table that is long enough to go onto second page. What I would like to achieve is to SPAN 4 rows on the second page. I do it using the follwing code in the TableStyle.
('SPAN', (0,38), (0,41))
Span for two rows works though. (‘SPAN’, (0,38), (0,39))
Here’s a code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from reportlab.platypus import SimpleDocTemplate, Table, LongTable, TableStyle, BaseDocTemplate, Frame, Paragraph, NextPageTemplate, PageTemplate
from reportlab.lib.pagesizes import letter, inch
from reportlab.lib import colors
def testPdf():
doc = BaseDocTemplate("testpdf.pdf",pagesize=letter,
rightMargin=72,leftMargin=72,
topMargin=72,bottomMargin=18, showBoundary=True)
width, height = letter
print width
print height
elements = []
datas = []
for x in range(1,50):
datas.append(
[x,x+1]
)
t=LongTable(datas)
tTableStyle=[
('SPAN', (0,38), (0,41)),
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
('BOX', (0,0), (-1,-1), 0.25, colors.black),
]
t.setStyle(TableStyle(tTableStyle))
elements.append(t)
frameT = Frame(doc.leftMargin, doc.bottomMargin, doc.width, doc.height, id='normal')
doc.addPageTemplates([PageTemplate(id='OneCol',frames=frameT)])
doc.build(elements)
if __name__ == '__main__':
testPdf()
I ran your sample code and saw the same problem. For anyone coming along who might be interested, the error that results is:
Sort answer: this is a bug in ReportLab and you’ll need to report it to the developers.
Long answer: I’ve seen problems with splitting before. There were (and apparently still are) situations that confuse the algorithm when splitting is plainly possible but the algorithm ends up throwing an error because it can’t figure out which page to put it on. It can happen at weird times when you wouldn’t expect it, and I know of no especially good work around other than to manually split things yourself (or to wrap content in
KeepTogetherflowables, but that won’t work in your situation).