如何将新字体添加到pyfpdf

时间:2012-04-05 12:13:08

标签: python fonts web2py fpdf true-type-fonts

我试图将dejavucondensed.ttf复制到pyfpdf / font / 但是当我尝试时没有运气

>>> from pyfpdf import *
>>> p = FPDF()
>>> p.add_font('dejavucondensed')
SyntaxError: Non-ASCII character '\xfd' in file pyfpdf/font/dejavucondensed.font 
on line 2, 
but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

1 个答案:

答案 0 :(得分:0)

这可能是Unicode /编码问题(请参阅PEP linked in the message)。我这里没有安装pypdf,但根据reference documentation for add_font,您需要使用uni参数:

pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', uni=True)