[reportlab-users] Understanding Wordwrap, esp. in tables

Andrew Smart smart at smart-knowhow.de
Wed Nov 14 12:25:05 EST 2007





> Von: reportlab-users-bounces at reportlab.com

> [mailto:reportlab-users-bounces at reportlab.com] Im Auftrag von

> Robin Becker

> Gesendet: Mittwoch, 14. November 2007 16:04

> An: Support list for users of Reportlab software

> Betreff: Re: [reportlab-users] Understanding Wordwrap, esp. in tables

>

> Andrew Smart wrote:

>

> Paragraphs can do both the above. The attributes values in

> the styles are rather old fashioned though.

>

> from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER,

> TA_JUSTIFY


Hmmm... I think this was the right pointer. I do a Table() call
with a sequence of sequences which are a mix of unicode strings
and paragraphs.

To be able to use TA_LEFT I'll have to convert the relevant
strings to Paragraphs with a corresponding style.


> I think the TA stands for "text align", but it's pretty

> stupid to have these numeric constants rather than some

> sensible string values. If you set a paragraphs style

> alignment attribute to one of these you'll get differing behaviour.

>

> Again be aware that everything in python is by reference so if you do

>

> sty=ParagraphStyle(......,alignment=TA_LEFT)

> P0 = Paragraph('aaaa',style=sty)

>

> sty.alignment=TA_RIGHT

> P1=Paragraph('bbbbb',style=sty)

>

> then it's highly likely both paragraphs will get right

> aligned since both have a reference to the same style.

> Instead of re-use just make a new style with the first as parent ie

>

> sty = ParagraphStyle(parent=sty,.......,alignment=TA_RIGHT)


Thanks for the hint. I'm already having a good set of partly independent
style objects, so this kind of error won't happen.

Thanks!

Andrew



More information about the reportlab-users mailing list