[reportlab-users] Font Helvetica always used?
Robin Becker
robin at reportlab.com
Fri Jun 19 07:11:34 EDT 2015
On 19/06/2015 11:30, Andy Robinson wrote:
........
> If we did
> initial_fontName = "MyFancyFont"
> which is not one of the standard 14, then presumably we'd also need to
> ensure they registered a font with that name? When would we complain
> that "myfancyfont.ttf" had not been registered - on first use, or on
> saving the canvas?
.......
any initialFontName would still need support and the error happens as soon as we
try to use it in _make_preamble.
Traceback (most recent call last):
File "C:\code\hg-repos\reportlab\tmp\thello.py", line 21, in <module>
canv = Canvas('thello.pdf',initialFontName='myfancyfont')
File "c:\code\reportlab\pdfgen\canvas.py", line 309, in __init__
self._make_preamble()
File "c:\code\reportlab\pdfgen\canvas.py", line 401, in _make_preamble
font = pdfmetrics.getFont(self._fontname)
File "c:\code\reportlab\pdfbase\pdfmetrics.py", line 673, in getFont
return findFontAndRegister(fontName)
File "c:\code\reportlab\pdfbase\pdfmetrics.py", line 655, in findFontAndRegister
face = getTypeFace(fontName)
File "c:\code\reportlab\pdfbase\pdfmetrics.py", line 612, in getTypeFace
return _typefaces[faceName]
KeyError: 'myfancyfont'
if I now run the modified Canvas with
from reportlab.pdfgen.canvas import Canvas
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase.pdfmetrics import registerFont, registerFontFamily
registerFont(TTFont('arial','arial.ttf'),)
registerFont(TTFont('arial-bold','arialbd.ttf'),)
registerFont(TTFont('arial-italic','ariali.ttf'),)
registerFont(TTFont('arial-bolditalic','arialbi.ttf'),)
registerFontFamily('arial',
normal='arial',
bold='arial-bold',
italic='arial-italic',
boldItalic='arial-bolditalic',)
canv = Canvas('thello.pdf',initialFontName='arial')
canv.drawString(72,72,'Hello World')
canv.save()
then the output PDF doesn't contain 'Helvetica'.
--
Robin Becker
More information about the reportlab-users
mailing list