[reportlab-users] How to change PDF document encoding to iso-8859-15

Enis Afgan eafgan at emory.edu
Wed Jan 19 22:58:13 EST 2011


Hello,
I'm getting familiar with ReportLab but I ran into an issue I haven't been
able to resolve for a few of hours now so I decided to ask here.
I need to generate PDF documents using iso-8859-15 (latin-9) encoding but
it's just not happening. I'm running OSX 10.6.6 with Python 2.7 and
ReportLab 2.5. The documents are being generated from within a Django (v1.3)
app and here is the relevant view code:
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=file.pdf'
p = canvas.Canvas(response)
x = u"četvrtak"
y = "šteta"
p.drawString(100, 780, x.encode('iso-8859-15'))
p.drawString(100, 780, y)

Here is a screenshot of the resulting PDF:
http://img171.imageshack.us/img171/5443/screenshot20110119at104.png

If I just print to the terminal x.encode('iso-8859-15'), the outcome is as
expected (
http://img146.imageshack.us/img146/1132/screenshot20110119at105.png).
It seems that the reason 'š' is printing fine is because it's part of the
WinAnsi encoding while 'č' is not but anything else I've tried did not work.
I tried using utf-8 and couple other encodings, but to no avail...

Any suggestions would be greatly appreciated,
Enis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20110119/d7f658ac/attachment.htm>


More information about the reportlab-users mailing list