Searching for UTF8 capable font for REPORTLAB

A

Andreas Jung

Reportlab has some problems with creating PDFs from UTF8 encoded text. For
this reason
they are using a truetype font rina.ttf which looks *very ugly*. Does
anyone know of a
suitable free available truetype font that works with UTF8?

-aj
 
J

JanC

Andreas Jung said:
Reportlab has some problems with creating PDFs from UTF8 encoded text.
For this reason they are using a truetype font rina.ttf which looks
*very ugly*. Does anyone know of a suitable free available truetype
font that works with UTF8?

AFAIK a "UTF8 capable TrueType font" doesn't exist; but most modern
TrueType fonts have Unicode character tables?

(From the screenshots in the userguide.pdf Rina doesn't look ugly IMHO, but
it's clearly not intended for large pieces of body text. :)
 
M

Marijan Tadin

Try following code, replace value of my_location_of_TTF with your
location of TTF (of course you should have TT fonts somewhere on your
machine, on windows they are allways there, AFAIK you can download them
for linux):

There is also mailing list on ReportLabs website, it is where I found
the hint how to use ReportLab and Unicode.


from reportlab.pdfgen import canvas
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont

canv = canvas.Canvas('test_03.pdf')
fontname = 'CS'

my_location_of_TTF = 'C:\WINNT\FONTS\comic.TTF'

pdfmetrics.registerFont(TTFont(fontname,my_location_of_TTF))
a=u'\u010d\u0107\u017e\u0161\u0111\u010c\u0106\u017d\u0160\u0110'
canv.setFont(fontname,10)
canv.drawString(50,100,'Some text:'+a.encode('UTF8'))
canv.save()
 
M

Marijan Tadin

Try following code, replace value of my_location_of_TTF with your
location of TTF (of course you should have TT fonts somewhere on your
machine, on windows they are allways there, AFAIK you can download them
for linux):

There is also mailing list on ReportLabs website, it is where I found
the hint how to use ReportLab and Unicode.


from reportlab.pdfgen import canvas
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont

canv = canvas.Canvas('test_03.pdf')
fontname = 'CS'

my_location_of_TTF = 'C:\WINNT\FONTS\comic.TTF'

pdfmetrics.registerFont(TTFont(fontname,my_location_of_TTF))
a=u'\u010d\u0107\u017e\u0161\u0111\u010c\u0106\u017d\u0160\u0110'
canv.setFont(fontname,10)
canv.drawString(50,100,'Some text:'+a.encode('UTF8'))
canv.save()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top