简体   繁体   English

使用reportlab生成pdf的长表

[英]Generating a pdf of long tables with reportlab

I am dealing with generating a PDF from a huge data list. 我正在处理从巨大的数据列表生成PDF。

There is no fancy styling or formatting involved. 没有花哨的样式或格式。 It's just that the data is a huge list (about 500 rows and 500 columns). 只是数据是一个巨大的列表(大约500行和500列)。 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. 目前,根据页面大小在多个页面之间拆分行没有问题,但由于500列不适合一页,因此列被截断。 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)

I think the best option for a PDF print might be to actually declare a pagesize large enough to handle the data. 我认为PDF打印的最佳选择可能是实际声明一个足够大的页面大小来处理数据。 For instance if each block of the grid is 1x1 inch and one inch padding on each side, then try doing something like: 例如,如果网格的每个块都是1x1英寸并且每侧有一英寸填充,那么尝试执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM