[reportlab-users] Problems using CJK Paragraphs in tables

Kirby, Dave Dave_Kirby at bmc.com
Thu Feb 3 11:11:22 EST 2011

> -----Original Message-----

> From: Robin Becker [mailto:robin at reportlab.com]

> Sent: 01 February 2011 16:57

> To: reportlab-users

> Cc: Kirby, Dave

> 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.

> --

> Robin Becker

I don't think that is the case here. I have tried cutting down the size of the data so that there is no way it should be too big, but I still get the exception. I have also just tried replacing the percent sizes with absolute sizes and it works fine, but I don't want to have the table size hard-coded, e.g. in case the user wants the PDF as letter instead of A4.

Here are the variations of the function I have tried to calculate the column widths. In each case the data parameter is a list of list of strings to put in the table, and I weight the column widths according to the length of the data in that column, so columns that only have short text are half the width of the others. For the second and subsequent code snippets I am leaving out the code that calculates the weights since it is unchanged.

1) Hard coding the table width to 15 cm. This succeeds, but assumes I know how wide the table should be in advance:

def calcColumnWidths(self, data):
if len(data) <=1:
return None

columns = len(data[0])
weights = []
for column in xrange(columns):
max_width = max(len(row[column]) for row in data[1:])
if max_width <= self.THIN_COLUMN_THRESHOLD:

base_width = 15 * cm / sum(weights)
return [ (weight*base_width) for weight in weights]

2) Pass all the widths as percentages. This fails with the "LayoutError: Splitting error" exception, even though the table should be the same size as (1). I have also experimented with rounding the percentages to integers and making sure they sum to exactly 100%, with no difference in the result.

def calcColumnWidths(self, data):
base_width = 100.0 / sum(weights)
return ["%f%%" % (weight*base_width) for weight in weights]

3) replacing the last width with "*". This creates the PDF but the last cell may be of arbitrary width and the contents not wrapped.

def calcColumnWidths(self, data):
base_width = 100.0 / sum(weights)
return ["%f%%" % (weight*base_width) for weight in weights[:-1]] + ['*']

I will try to create a stand-alone example that demonstrates the problem, but it may take a few days since I have other work to do.

I forgot to mention that I am using reportlab 2.5 on Python 2.6.5.


More information about the reportlab-users mailing list