[reportlab-users] Long word in paragraph in table cell

Andy Robinson andy at reportlab.com
Fri Aug 31 10:38:48 EDT 2007


On 30/08/2007, Simon Metson <s.metson at bristol.ac.uk> wrote:

> Hello,

> I'm writing a document using Reportlab, and so far so good. However, I have

> a table, whose contents are paragraphs (though there's no need for them to

> be). The contents of some of the table cells will be long strings without

> spaces, strings longer than the width of the cell. I'd like a way to

> automatically split the string,


We don't do hyphenation at the moment so it's your problem to break up
the text prior to formatting.

Assuming it only happens in some very specific situations and you know
which columns are prone to it, and you know the table cell width, font
name and size, you can use the
reportlab.pdfbase.pdfmetrics.stringWidth(..) function to size your
text. I suggest writing a function which splits up these mega-words
into a list of shorter ones. (Or, use Courier and count characters
not points...). You can then either put a list of strings in each
cell, or combine them with newlines into preformatted objects.

If you feel very brave you could contribute a hyphenation feature for
our Paragraph classes, but there is a lot of optimised and rather
scary code to work through there...


Best Regards,

Andy Robinson


More information about the reportlab-users mailing list