[reportlab-users] RenderPMError when using TTF in bitmaps

Dinu Gherman gherman at darwin.in-berlin.de
Sat Jan 13 04:34:54 EST 2018


Hello!

in a toy project I register a TrueType font, use it in a Drawing and save that as a PNG (see code below), but I’m getting a warning and traceback, that suggests I need PFB files for that font. I’ve reproduced this at least with one other TTF, too.

I believe I did that kind of thing without any trouble some years ago, or maybe I have false memories? Any ideas? This is on Python 3.6 and reportlab 3.4.0.

Cheers,

Dinu


from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase import pdfmetrics
from reportlab.graphics.shapes import Drawing, String
from reportlab.graphics import renderPM

ttf = TTFont('Code2000', 'fonts/Code2000.ttf')
pdfmetrics.registerFont(ttf)
d = Drawing(500, 500)
fn, fs = 'Code2000', 24
text = String(0, 0, "foo bar", fontName=fn, fontSize=fs)
d.add(text)
renderPM.drawToFile(d, "foo_bar.png", fmt="PNG", dpi=72)


Warn: Can't find .pfb for face 'b'Code2000‘'
[...]
[...]/lib/python3.6/site-packages/reportlab/graphics/renderPM.py in _setFont(gs, fontName, fontSize)
    249         except:
    250             s1, s2 = list(map(str,sys.exc_info()[:2]))
--> 251             raise RenderPMError("Can't setFont(%s) missing the T1 files?\nOriginally %s: %s" % (fontName,s1,s2))
    252         gs.setFont(fontName,fontSize)
    253

RenderPMError: Can't setFont(Code2000) missing the T1 files?
Originally <class 'AttributeError'>: 'TTEncoding' object has no attribute ‚v
ector'




More information about the reportlab-users mailing list