Hi, I have tried again to use fpdf.
1st try:
from gluon.contrib.fpdf import FPDF
pdf = FPDF('P', 'mm', 'A4')
pdf.set_font('Arial', 'B', 16)
pdf.cell(40,10,'Hello World')
response.headers['Content-Type'] = 'application/pdf'
return XML(pdf.output('', 'S'))
Ok, that's simple and it works fine.
2nd try:
Now I want to use the unicode version.
Before you can use UTF-8, you have to install at least one Unicode font in the font directory (or system font folder).
But there is no font directory in fpdf!
It would be nice to have a complete example how to use fpdf in web2py!
After some trials I had to copy the font directory containing a lot of "DejaVu*"-files to the gluon/contrib/fpdf directory.
The structure is: gluon/contrib/fpdf/font
from gluon.contrib.fpdf import FPDF
pdf = FPDF('P', 'mm', 'A4')
pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', uni=True)
pdf.set_font('DejaVu', '', 14)
pdf.cell(40,10,'Hello World äöü€')
response.headers['Content-Type'] = 'application/pdf'
return XML(pdf.output('', 'S'))
And now I get an error message:
<type 'exceptions.ValueError'> could not convert string to float
web2py™ | Version 2.12.3-stable+timestamp.2015.08.19.00.18.03 |
---|
Python | Python 2.7.6: /usr/local/bin/python (prefix: /usr) |
---|
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. | Traceback (most recent call last): File "/home/www-data/web2py/gluon/restricted.py", line 227, in restricted exec ccode in environment File "/home/www-data/web2py/applications/m_abschluss/controllers/test.py", line 54, in <module> File "/home/www-data/web2py/gluon/globals.py", line 412, in <lambda> self._caller = lambda f: f() File "/home/www-data/web2py/applications/m_abschluss/controllers/test.py", line 26, in test pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', uni=True) File "/home/www-data/web2py/gluon/contrib/fpdf/fpdf.py", line 432, in add_font font_dict = pickle.load(fh) ValueError: could not convert string to float |
What is the right way to use fpdf with the whole unicode character set in web2py?