我正在按照this link将ReportLabs集成到Django中。我正确地完成了所有操作,但出现错误消息-
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包中不可用。我如何从这里开始?
最佳答案
要注册字体:
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)