ReportLabs Django集成

时间:2013-11-26 09:41:34

标签: python django reportlab

我正在关注this link以在Django中集成ReportLabs。我做的一切都正确,但我得到一个错误 -

Exception Type: RenderPMError

Exception Value:    
Can't setFont(Times-Roman) missing the T1 files?
Originally <type 'exceptions.TypeError'>: makeT1Font() argument 2 must be string, not None

我哪里出错了?我猜这个字体在ReportLabs包中不可用。我该如何从这里开始?

2 个答案:

答案 0 :(得分:2)

注册字体:

import os
from reportlab.pdfbase import pdfmetrics  
from reportlab.pdfbase.ttfonts import TTFont

pdfmetrics.registerFont(TTFont("Arial", os.path.join(settings.PROJECT_ROOT, 'static', 'fonts', 'arial.ttf'))) # here i have my fonts for PDF's

使用它,例如:

page = canvas.Canvas(response, pagesize=A4, pageCompression = 0)

canvas.setFont('Arial',9)

答案 1 :(得分:0)

您必须下载字体并将其放入ReportLabs包中。

您需要这些文件:

http://www.reportlab.com/ftp/fonts/pfbfer.zip

将它们解压缩:

/path/to/your/python/site-packages/reportlab/fonts