Praful Bagai
Praful Bagai

Reputation: 17372

ReportLabs Django Integration

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?

Upvotes: 2

Views: 3097

Answers (2)

McAbra
McAbra

Reputation: 2514

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)

Upvotes: 2

Jay
Jay

Reputation: 2569

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

Upvotes: 1

Related Questions