[reportlab-users] Re: reportlab-users digest, Vol 2 #116 - 3 msgs

sakesun reportlab-users@reportlab.com
Wed, 26 May 2004 10:14:15 +0700

> Tahoma contains almost all the world's languages.  If you have
> any other TrueType fonts which definitely contain Thai characters
> in UTF8, they should work.  

I've tried 'Arial Unicode MS', which is universal font, but it's not working.
 That's why I wonder what's special about 'Tahoma'

> > And I also have no idea why I have to manually "encode('utf-8')" for 
> > every unicode text I draw.
> Yes, this sounds like a bug.  We should really accept unicode
> characters.  
> Can you send us some 'escaped thai text' e.g. send the results of
>   u.'thai text goes here'.encode('utf-8'), and a link on the web
> to 'what it should look like' ? This will help us.

here's the code

from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont

pdfmetrics.registerFont(TTFont('Tahoma', 'c:\\Windows\\Fonts\\TAHOMA.TTF'))
pdfmetrics.registerFont(TTFont('Arial Unicode MS',

SAWASDEE = u'"\u0e2a\u0e27\u0e31\u0e2a\u0e14\u0e35"'

def hello(c, x, y, fontname, encoding=None):
    c.setFont(fontname, 14)
    string = SAWASDEE + u' means hello'
    if encoding:
        string = string.encode(encoding)
        c.drawString(x, y, string)
    except Exception, e:
        c.drawString(x, y, str(e))
c = canvas.Canvas("c:\\temp\\Hello.pdf", pagesize=A4)
hello(c, 100, 700, 'Tahoma')
hello(c, 100, 600, 'Tahoma', 'utf-8')    # this is the only line that works
hello(c, 100, 500, 'Arial Unicode MS')
hello(c, 100, 400, 'Arial Unicode MS', 'utf-8')