[reportlab-users] Forcing usage of DejaVu fonts instead of standardfonts in PDF

Sorin Sbarnea sorin.list at intersol.ro
Sun Dec 16 18:15:40 EST 2007


I have several problems with missing special characters in default fonts and I want to force the DejaVu fonts (last release) instead of the default Times/Helvetica/Courier using:

pdfmetrics.registerFont(TTFont('Times-Roman', 'DejaVuSerif.ttf'))
pdfmetrics.registerFont(TTFont('Times-BoldItalic', 'DejaVuSerif-BoldItalic.ttf'))
pdfmetrics.registerFont(TTFont('Times-Bold', 'DejaVuSerif-Bold.ttf'))
pdfmetrics.registerFont(TTFont('Times-Italic', 'DejaVuSerif-Italic.ttf'))

pdfmetrics.registerFont(TTFont('Helvetica', 'DejaVuSans.ttf'))
pdfmetrics.registerFont(TTFont('Helvetica-BoldItalic', 'DejaVuSans-BoldOblique.ttf'))
pdfmetrics.registerFont(TTFont('Helvetica-Bold', 'DejaVuSans-Bold.ttf'))
pdfmetrics.registerFont(TTFont('Helvetica-Italic', 'DejaVuSans-Oblique.ttf'))

pdfmetrics.registerFont(TTFont('Courier', 'DejaVuSansMono.ttf'))
pdfmetrics.registerFont(TTFont('Courier-Bold', 'DejaVuSansMono-Bold.ttf'))
pdfmetrics.registerFont(TTFont('Courier-BoldItalic','DejaVuSansMono-BoldOblique.ttf'))
pdfmetrics.registerFont(TTFont('Courier-Italic', 'DejaVuSansMono-Oblique.ttf'))

The first problem is seams that i receive:
File "trml2pdf.py", line 736, in <module>
print parseString(file(sys.argv[1], 'r').read()),
File "trml2pdf.py", line 724, in parseString
r.render(fp)
File "trml2pdf.py", line 234, in render
pt_obj.render(self.dom.documentElement.getElementsByTagName('story'))
File "trml2pdf.py", line 713, in render
self.doc_tmpl.build(fis)
File "/usr/lib/python2.5/site-packages/reportlab/platypus/doctemplate.py", line 730, in build
self._startBuild(filename,canvasmaker)
File "/usr/lib/python2.5/site-packages/reportlab/platypus/doctemplate.py", line 693, in _startBuild
pageCompression=self.pageCompression)
File "/usr/lib/python2.5/site-packages/reportlab/pdfgen/canvas.py", line 183, in __init__
self._make_preamble()
File "/usr/lib/python2.5/site-packages/reportlab/pdfgen/canvas.py", line 245, in _make_preamble
iName = self._doc.getInternalFontName(self._fontname)
File "/usr/lib/python2.5/site-packages/reportlab/pdfbase/pdfdoc.py", line 267, in getInternalFontName
raise PDFError, "getInternalFontName(%s) called for a dynamic font" % repr(psfontname)
reportlab.pdfbase.pdfdoc.PDFError: getInternalFontName('Helvetica') called for a dynamic font

I've found a hack on the forum that I should modify in canvas.py the _make_preamble to this:
def _make_preamble(self):
self._preamble = ''

This will not give any erros to me but somehow it does still not work for Helvetica (just the simple one, the variants like bold,italic are working). Helvetica seams to map to the default fonts(looks like an Arial to me)

Changing the name of the font in RML files is not an option. The entire idea is to change the font set without changing the templates. Just for your info: I've tried to change the font name to Helvetica2 in RML and on the registerFont and it does work, but i need to make it work for "Helvetica" because I can't "update" the RML files from the project.

Any idea?

--
Sorin Sbarnea


More information about the reportlab-users mailing list