[reportlab-users] utf8 text

Andy reportlab-users@reportlab.com
Tue, 10 Aug 2004 12:47:36 -0500


How do I get reportlab's para and Paragraph flowables to use utf-8 unicode 
strings?  Specifically, I want to use characters like smart quotes, curly 
commas, etc, that are submitted through the web by our users.  An example 
would be:

styles = getSampleStyleSheet()\
Paragraph(u'u\2019',styles['Normal'])

However, when I try this, I get the following traceback when building using a 
SimpleDocTemplate:

  Module reportlab.platypus.doctemplate, line 801, in build
  Module reportlab.platypus.doctemplate, line 631, in build
  Module reportlab.platypus.doctemplate, line 549, in handle_flowable
  Module reportlab.platypus.frames, line 120, in _add
  Module reportlab.platypus.para, line 1288, in wrap
  Module reportlab.platypus.para, line 158, in format
  Module reportlab.platypus.para, line 290, in fitLine
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 
0: ordinal not in range(128)

Using this string: u'u\2019'.encode('utf8') will run without errors, but the 
text becomes a couple random characters.

I'd really appreciate any help you can give.
Andy