[reportlab-users] Character Encoding
Uli Schrempp
schrempp at syslab.com
Wed Apr 27 03:32:01 EDT 2005
Hi Tim!
Thanks for your reply. Taking the windows arial-font solved the problem.
My the encoding mechanism is correct. I get a utf-8-encoded string with
greek letters and want to transform it into an iso8859-7-encoded string.
I just changed the font and everything worked fine.
BR uli
Tim Roberts schrieb:
> On Fri, 22 Apr 2005 13:09:51 +0200, Uli Schrempp <schrempp at syslab.com>
> wrote:
>
>> I'm trying to write an ISO 8859-7 (greek letters) string into a PDF
>> like this:
>> text = unicode(greek_letters, 'utf-8').encode('iso8859-7')
>> myCanvas.setFont('helvetica', 16)
>> myCanvas.drawCentred String( x, y, text)
>>
>> But I get no greek letters written ...
>> What have I to improove?
>>
>>
>
> Two problems. First, I suspect you have an encoding problem here. What
> that code says is that "greek_letters" is a string in UTF-8, which you
> then convert to ISO8859-7 and send to ReportLab. However, ReportLab
> doesn't understand ISO8859-7 -- it understands UTF-8. What IS the
> variable "greek letters"? Is it actually an ISO8859-7 string? If so,
> you want this:
>
> text = greek_letters.decode('iso8859-7').encode('utf-8')
>
> Convert the ISO8859-7 to Unicode, then convert the Unicode to UTF-8.
>
> Second, I'm not sure the Poscscript fonts (like Helvetica) understand
> UTF-8 at all, and I don't think they have any Greek characters. UTF-8
> certainly works with TrueType fonts. I just tried this, and it worked:
>
> pdfmetric.registerFont( TTFont( 'Arial1', 'arial.ttf') )
> u = u"\N{greek capital letter delta}\N{greek capital letter gamma}"
> u1 = u.encode('utf-8')
> c.setFont( 'Arial1', 36 )
> c.drawString( 80, 600, u1 )
>
--
Ulrich Schrempp
schrempp at syslab.com, SYSLAB.COM GmbH, Bonner Platz 1, 80803 München
Tel: +49 89 3063589-0, Fax: +49 89 3063589-9, http://www.syslab.com
More information about the reportlab-users
mailing list