Generating a pdf of long tables with reportlab

牧云@^-^@ 提交于 2019-12-08 09:48:04

问题


I am dealing with generating a PDF from a huge data list.

There is no fancy styling or formatting involved. It's just that the data is a huge list (about 500 rows and 500 columns). Here is my code. Currently it will have no problem splitting rows across multiple pages depending on the page size, but the columns are being cut off since 500 columns don't fit in one page. I would also like to split columns across different pages as well. Each cell entry is just an integer. How can I achieve that?

from reportlab.lib import colors
from reportlab.lib.units import cm
from reportlab.lib.pagesizes import A0
from reportlab.platypus import SimpleDocTemplate, LongTable, TableStyle


elements = []
doc = SimpleDocTemplate(output, pagesize=A0)
t = LongTable(data)
t.setStyle(TableStyle([('INNERGRID', (0,0), (-1, -1), 0.25, colors.black), 
                       ('BOX', (0, 0), (-1, -1), 0.25, colors.black), 
                     ]))
elements.append(t)
doc.build(elements)

回答1:


I think the best option for a PDF print might be to actually declare a pagesize large enough to handle the data. For instance if each block of the grid is 1x1 inch and one inch padding on each side, then try doing something like:

doc = SimpleDocTemplate(output, pagesize=(502*inch, 502*inch) )


来源:https://stackoverflow.com/questions/9841546/generating-a-pdf-of-long-tables-with-reportlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!