Table cell (SPAN) across pagebreak
Kyle Dunaway <[email protected]>
| Newsgroups | gmane.comp.python.reportlab.user |
|---|---|
| Message-ID | <[email protected]> |
I have attached a simple example that should explain my larger problem. I am creating a table, and as I am creating the table I am reducing redundancy in the table columns (if the cell above has the same word, leave cell empty) If one table cell is larger than a whole page, ReportLab fails to generate the PDF. On line 28, adjust the span length and you will see what I am talking about. I have spend some time looking around and this problem seems to have not been fixed for a long time. The workarounds I found seem pretty ugly (making the PDF 1 page, but then printing is out of the question) Anyone have any idea on a fix? Thanks for reading.
test.py
(text/x-python, 990 B)
import sys
from reportlab.lib import colors
from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
from reportlab.platypus import SimpleDocTemplate, Paragraph, Image, Table, TableStyle, PageBreak
def main():
folderToSaveReport = 'C:/Temp/test.pdf'
styles = getSampleStyleSheet()
table_data = [
["Column 1", "Column 2"]
]
for i in range(100):
table_data.append([i+1, i+1])
table_style = TableStyle([
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
('BOX', (0,0), (-1,-1), 0.25, colors.black),
])
doc = SimpleDocTemplate(folderToSaveReport, pagesize=letter)
mainPDF=[]
table_style.add('SPAN',(0,0),(0,35))
table = Table(table_data)
table.setStyle(table_style)
mainPDF.append(table)
try:
doc.build(mainPDF)
print("Success")
except Exception as e:
print("Error:", str(e))
if __name__ == '__main__':
main()