[reportlab-users] Problems using CJK Paragraphs in tables
robin at reportlab.com
Tue Feb 1 11:56:48 EST 2011
On 01/02/2011 15:07, Kirby, Dave wrote:
> I have a program that pulls user-generated data out of a database and generates a PDF with some of the data formatted into tables. The text for each cell is inside a Paragraph object. The data can be of an arbitrary size and can contain very/long/strings/of/text/with/no/spaces/in/such/as/paths/to/files, which were leaking out into adjacent cells.
> After much experimentation I have implemented the following solution:
> 1) When I create the table I inspect the text for each cell by splitting it into words. If any word is longer than a certain threshold I use a paragraph with wordWrap="CJK", otherwise I use a Paragraph with default word wrapping.
> 2) If the overall text for a cell is longer than 500 characters I chop out the middle and replace it with ellipsis. This is to stop reportlab throwing an exception if the cell can't fit on the page.
> 3) I set the table colWidths parameter to a list of percentages. These should sum to 100%, except for rounding errors.
> However I am still having problems, and I think the issues are with Reportlab's code, not in mine.
> The first problem is from (3) above. I get an exception "LayoutError: Splitting error(n==2)", unless I replace the last width value with "*". I presume this has something to do with the widths not summing to exactly 100%.
> Secondly, setting the last width value to "*" results in the PDF being generated, but occasionally a table will be badly formatted. The column widths do not always respect the percentage values I give them, with the last column sometimes much wider than it should be. Also the text in the last column sometimes does not wrap at all, resulting in a column that is wider than the page it is on with the rest of the table pushed right outside the document.
> I am not sure if this is a problem solely with combining percentages and "*" in colWidths, or whether it is a combination of that and using CJK Paragraphs.
> Can anyone shed any light on this?
Usually the splitting problem results from content which is too long to be put
in a frame. That might be because a single cell is too long. Unfortunately we
don't split cells so a cell that's too long can make this problem happen. A
table cell that's too long is probably an indication of a problem somewhere.
More information about the reportlab-users