Search code examples
pythondatatablereportlab

Setting the table size in reportlab


I have a lot of different tables to create in one PDF document, all with difeerent amount of columns. Can you set the table to a certain size? At the moment some are larger then the pagesize and columns are missing and some are much smaller and just fill half a page.

def v2(lc):
                t=Table(lc)
                t.setStyle(TableStyle([('SPAN', (0, 1), (-1, 1)),('FONTSIZE',(0,1),(-1,1),15),
                                       ('ALIGN',(0,3),(-1,3),'CENTER'),
                                       ('INNERGRID', (0,3), (-1,-1), 0.25, colors.black),
                                       ('BOX', (0,3), (-1,-1), 1, colors.black)
                                       ]))
                elements.append(t)
                elements.append(PageBreak())

Solution

  • You can pass colWidths to Table(lc)

    I have 5 columns and I set width of each like this Table(lc, colWidths=[0.5*inch,0.7*inch,2*inch,2*inch, 1*inch])