[reportlab-users] Table question: how do I fix the width of specific columns while ensuring that text is wrapped?

Keng Onn Wong kwong at fortress.com
Thu Apr 3 22:16:55 EDT 2014


I am trying to generate a table that has fixed width columns, and from the documentation, I understand that this is done via passing a colWidths list of widths when the table is instantiated. E.g

table = Table(tableData, colWidths=[column_width1, column_width2, None, column_width3, column_width4, None]

and that "None" will let reportlab automatically determine the width. So far so good. However, the problem is when the text for a particular column becomes too long, and it starts accumulating all together in one messy black clump without wrapping over to the next line (within the same cell). So I tried to tackle this issue using a Paragraph Flowable, so that my tableData now looks something like this:

tableData = [['a', 'b', Paragraph("long string of text here", some_style), 'abc'], ...]

However, now I find that my table, when printed out to pdf, now auto-sizes to take up the entire page width (or frame-width). Previously, when I was just using plain strings (and no Paragraph Flowables), the table took up just enough width to display the data, but now with the inclusion of the Paragraph flowable, the entire table takes up the whole width of the page/frame. Am I missing something here? Coz I would like to print a table with wrapped-around text for that fixed column but yet which fits the other data columns just right (those with 'None' column widths).

Thanks and regards,
Keng Onn

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20140404/fe3abe0f/attachment.html>

More information about the reportlab-users mailing list