[reportlab-users] UTF8 Encoded Strings

Robin Becker robin at reportlab.com
Wed Oct 31 09:59:52 EDT 2007


Rich Shepard wrote:

> How do I configure ReportLab to handle UTF8 strings in textobjects?

>

> My data look like this tuple: (u'Jobs', u'Infrastructure'), and when I

> try

> to print them using this for loop

>

> for pairs in pairData:

> textobject.textLine(pairs)

> pg.drawText(textobject)

>

> this error is returned:

>

> Traceback (most recent call last):

> File "learnRL.py", line 80, in ?

> econRun()

> File "learnRL.py", line 70, in econRun

> textobject.textLine(pairs)

> File "/usr/lib/python2.4/site-packages/reportlab/pdfgen/textobject.py",

> line 372, in textLine

> self._code.append('%s T*' % self._formatText(text))

> File "/usr/lib/python2.4/site-packages/reportlab/pdfgen/textobject.py",

> line 333, in _formatText

> text = text.decode('utf8')

> AttributeError: 'tuple' object has no attribute 'decode'

>

> Do I need to explicitly convert the list of tuples before feeding them to

> ReportLab?

>

> Rich

>

I guess you need to use either a single utf8 encoded string or a single unicode
string as input to that method. This works fine

textobject.textLine(u'This is silly!')

the textLine method has a single argument called text.
--
Robin Becker


More information about the reportlab-users mailing list