[reportlab-users] Problems with certain Greek letters and unicode

Peter Cock p.j.a.cock at googlemail.com
Tue Aug 12 12:53:18 EDT 2008


I'm trying to include particular greek letters in a PDF file, and have
been trying to do this with the canvas drawString and
drawCentredString methods. In particular I want an upper case omega,
Unicode u"\u03a9", but this is not the only problem I am seeing -
upper case Delta and lower case mu are also failing.

The following bit of code should illustrate the problem I am seeing
using ReportLab 2.1 with Python 2.5.2 on Apple Mac OS X 10.5 Leopard,

import reportlab
from reportlab.pdfgen import canvas
from reportlab.lib.units import cm

y_scale=0.5*cm
margin = 1*cm
letters = [eval('u"\\u%04x"' % i) for i in \
range(int("0391",16), int("03a9",16)+1) +\
range(int("03b1",16),int("03c9",16)+1)]
c = canvas.Canvas("greek.pdf", (8*cm, 2*margin + len(letters)*y_scale))
c.setFont('Helvetica', 12)
for i,a in enumerate(letters) :
c.drawString(1*cm, margin + i*y_scale, a)
c.setFont('Symbol', 12)
for i,a in enumerate(letters) :
c.drawString(2*cm, margin + i*y_scale, a)
c.setFont('Courier', 12)
for i,a in enumerate(letters) :
c.drawString(3*cm, margin + i*y_scale, a)
c.setFont('Times-Roman', 12)
for i,a in enumerate(letters) :
c.drawString(4*cm, margin + i*y_scale, a)
c.drawString(5*cm, margin + i*y_scale, repr(a))
c.drawCentredString(4*cm, margin + len(letters)*y_scale,
"ReportLab %s" % reportlab.Version)
c.showPage()
c.save()

This should print out the greek alphabet using their unicode values,
however the following are showing as black rectangles (in all four
fonts):

U0394 - missing, upper case delta
U03A2 - missing, because there is no uppercase variant of sigma at the
end of a word
U03A9 - missing, upper case omega
U03BC - missing, lower case mu

I can attach the PDF file if it helps. Any advice on how to get the
missing three characters would be welcome.

Thanks

Peter


More information about the reportlab-users mailing list