[reportlab-users] TTF, Platypus & Unicode...
Marius Gedminas
reportlab-users@reportlab.com
Tue, 30 Jul 2002 14:28:45 +0200
On Tue, Jul 30, 2002 at 01:03:27PM +0200, Dinu Gherman wrote:
> Marius Gedminas:
>
> >Latin-1 is very different from UTF-8. (Actually the encoding of the
> >first 128 characters matches, but the rest is different.) If you have
> >Python 1.6 or later you can use stuff like
> >
> > utf8_string = unicode(latin1_string, "ISO-8859-1").encode("UTF-8")
>
> That's basically what I did in the test script as well, and it
> also just replaces the accented character with a blank. Have
> you run the file locally?
Here's a sample that works for me:
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
fontdir = '/usr/share/fonts/truetype/'
pdfmetrics.registerFont(TTFont('Arial', fontdir + 'Arial.ttf'))
from reportlab.pdfgen.canvas import Canvas
canvas = Canvas('foo.pdf')
canvas.setFont('Arial', 12)
canvas.drawString(100, 700, unicode("Lithuanian national characters: àèæûáðøûþ", "ISO-8859-13").encode("UTF-8"))
canvas.save()
Marius Gedminas
--
If you can't understand it, it is intuitively obvious.