Properly display accented characters

11 views
Skip to first unread message

Caesar

unread,
Apr 24, 2017, 4:02:05 PM4/24/17
to reportlab-users

I've been playing around with Python+Reportlab for a few days now, just for a personal project, but I am stuck trying to get Reportlab to properly draw accented characters on the PDF.


I've tried several different fonts. Nevertheless, the characters appear strangely spaced or don't appear at all. Please, see sample code below.


#!/usr/bin/python3
# -*- coding: utf-8 -*-

from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4

# Create a new canvas object to draw into
canv = canvas.Canvas("teste.pdf", pagesize=A4, bottomup=0);

canv.setFont("Helvetica", 11);
canv.drawString(100, 100, "Hello world!");
canv.drawString(100, 130, "Limões in Portuguese!");
canv.drawString(100, 150, "Dó Ré e Maçãs in Portuguese!");
canv.drawString(100, 170, "bē bān yá mó luò gē!");
canv.drawString(100, 190, "zǎo shang hǎo!");

# Save PDF to file
canv.save();

Thanks,
Reply all
Reply to author
Forward
0 new messages