ReportLab, PDF and Latin-1 characters

Jarek Zgoda jzgoda at usun.gazeta.pl
Wed Mar 12 21:57:53 CET 2003


Svenne Krap <usenet2002 at krap.dk> pisze:
 
> Being a native danish speaker, we are blessed with three extra letters
> :)
> Working with pdfgen, i get
> 
> <code>
> from reportlab.pdfgen import canvas
> c = canvas.Canvas("C:\\mypdf.pdf")
> c.setFont('Arial',12)
> c.setFont('Helvetica',12)
> c.drawString(10,10,'ćřĺ')
> </code>
> 
> but then, I get : 
> 
> <error>
> UnicodeError: ASCII encoding error: ordinal not in range(128)
> </error>
> 
> How do I manage to get Latin-1 (or even better full unicode) support
> in pdfgen ? 

ReportLab _is_ latin (1, 2, 9, 15...) compliant, it only needs unicode
string to be passed to text drawing routines. So:
c.drawString(10, 10, unicode('Zażółć gęślą jaźń'.decode('ISO8859-2')))
should write usual Polish compatibility test ;)

-- 
Jarek Zgoda
http://www.zgoda.biz/                        JID:zgoda at jabber.atman.pl




More information about the Python-list mailing list