FPDF add font not working

2,040 views
Skip to first unread message

peibol

unread,
Jul 7, 2013, 6:34:15 PM7/7/13
to web...@googlegroups.com
Hi there:

I'ts supposed we can add fonts from whatever the folder we want to FPDF. For example, in the static/fonts folder that I've created for this purpose:

def numbers():
class MyFPDF(FPDF, HTMLMixin):
pass
pdf=MyFPDF()
pdf.add_page()
pdf.add_font('DejaVu', '', URL('static','fonts/DejaVuSans.ttf', scheme=True, host=True), uni=True)
pdf.set_font('DejaVuSans','B',12)
pdf.cell(40,100,"Hello")
response.headers['Content-Type']='application/pdf'
return pdf.output(dest='S')

But I'm getting 
<type 'exceptions.RuntimeError'> TTF Font file not found: http://127.0.0.1:8083/myeducenter/static/fonts/DejaVuSans.ttf

And if I paste that URL in the browser I get the file...

Cheers
Pablo

Alan Etkin

unread,
Jul 7, 2013, 6:53:59 PM7/7/13
to web...@googlegroups.com
I'ts supposed we can add fonts from whatever the folder we want to FPDF. For example, in the static/fonts folder that I've created for this purpose:

It seems that .add_font takes an o.s. path as argument. See http://code.google.com/p/pyfpdf/wiki/AddFont

peibol

unread,
Jul 8, 2013, 3:31:37 AM7/8/13
to web...@googlegroups.com
Thanks Alan!

pdf.add_font('DejaVuSans', '', os.path.join(request.folder,'static','fonts/DejaVuSans.ttf'), uni=True)

It obviously works.
Reply all
Reply to author
Forward
0 new messages