ReportLabs Django集成 [英] ReportLabs Django Integration
本文介绍了ReportLabs Django集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在遵循此链接,将ReportLabs集成到Django中。我做了一切正常,但我收到一个错误 -
I'm following this link to integrate the ReportLabs in Django. I did everything correctly but I get an error saying -
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包中是不可用的。如何从这里进行?
Where I'm going wrong? I guess the font is not available in ReportLabs package. How do I proceed from here?
推荐答案
注册一个字体:
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)
这篇关于ReportLabs Django集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文