Create a Multilanguage PDF in Python

Rob Wolfe rwNOSPAM at NOSPAMsmsnet.pl
Sun Aug 20 11:08:14 EDT 2006


"Perseo" <mturillo at gmail.com> writes:

> Hi guys,
>
> I'm disprate with the Pdf Unicode. I try to create a class using ufpdf
> but some chars are not correct and now I would like try Python because
> a friend tolds me that it's very powerful.
> I need a simple script in Python that grab all Records from a MySql
> table and print in the pdf file.
>
> The languages stored in my db are about 25 and they are:
> Greek English French Hungarian Italian Lithuanian Dutch Portuguese
> Albanian
> Czech Danish German Spanish Estonian Finnish Irish Latvian Maltese
> Polish Romanian
> Russian Slovene Slovak Swedish

You can give reportlab [1] a try. It has support for TrueType fonts
and unicode translation using UTF-8. I used to use it for pdf files
with polish chars.

Some example code:

<code>
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfgen import canvas

pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf'))
c = canvas.Canvas("pl.pdf")
c.setFont("Verdana", 12)
c.drawString(100, 600, "Witaj, świecie!".decode("iso-8859-2").encode("utf-8"))
c.showPage()
c.save()
</code>


[1] http://www.reportlab.org/

-- 
HTH,
Rob



More information about the Python-list mailing list