ReportLabs Django Integration

南笙酒味 提交于 2019-12-02 06:45:42

问题


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

Where I'm going wrong? I guess the font is not available in ReportLabs package. How do I proceed from here?


回答1:


To register a font:

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

to use it, ex:

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

canvas.setFont('Arial',9)



回答2:


You have to download the fonts and place them in your ReportLabs package.

You need these files:

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

Unzip them in:

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


来源:https://stackoverflow.com/questions/20213339/reportlabs-django-integration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!