[reportlab-users] How to create special micr control character in Reportlab

Dinu Gherman gherman at darwin.in-berlin.de
Fri May 10 15:23:04 EDT 2013

Mike Driscoll:

> In the example I'm trying to duplicate, I need the funky sideways equals sign+square (looks kind of like an odd p) to wrap around a couple of the numbers. I found this wikipedia article, but I'm not sure how to implement it in a way that Reportlab will work with:


> http://en.wikipedia.org/wiki/Magnetic_ink_character_recognition


> Does anyone else know how to do this? Any tips or hints would be most appreciated! Thanks!

Does the CMC-7 TTF include these characters, as well? I can reproduce all these special CMC-7 characters nicely with a font named Code2000 (easy to find on the net), which is supposed to include all Unicode codepoints. See the code below and the attached PDF it generates.



from reportlab.lib.units import cm
from reportlab.pdfgen.canvas import Canvas
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont

font = TTFont("Code2000", "/Fonts/truetype/Code2000.ttf")

canv = Canvas("cmc-7.pdf")
canv.setFont("Code2000", 24)
canv.drawString(9*cm, 22*cm, "Hello World!")
cmc_chars = ' '.join([unichr(i) for i in range(0x2440, 0x244a)])
canv.drawString(9*cm, 21*cm, cmc_chars)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: cmc-7.pdf
Type: application/pdf
Size: 13662 bytes
Desc: not available
Url : <http://two.pairlist.net/pipermail/reportlab-users/attachments/20130510/14f6b7ec/attachment-0001.pdf>

More information about the reportlab-users mailing list