Closed GoogleCodeExporter closed 9 years ago
I've made a change to allow them, please update html.py:
https://pyfpdf.googlecode.com/hg/fpdf/html.py
Then, you need to load a ttf unicode font, and then pass it in <font> face
attribute:
pdf=MyFPDF()
# add utf8 font
pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', uni=True)
# first page:
pdf.add_page()
pdf.write_html(u"<font face='DejaVu'>Ąžuolas</font>")
For more info and complete code, see:
https://code.google.com/p/pyfpdf/wiki/Web2Py
Let me know if that works so I can update the docs and web2py contrib version
Original comment by reingart@gmail.com
on 27 Apr 2013 at 3:24
one more weird thing - combining html_write(..) and after it write(..) - gives
error
pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', uni=True)
pdf.set_font('DejaVu', '', 14)
pdf.write_html(u"<font face='DejaVu'>Ąžuolas</font>")
pdf.write(8, u'Ąžuolas') # causes error
***
pdf.write(8, u'Ąžuolas')
File "/home/nijole/Downloads/pyfpdf/fpdf/fpdf.py", line 837, in write
txt = self.normalize_text(txt)
File "/home/nijole/Downloads/pyfpdf/fpdf/fpdf.py", line 1045, in normalize_text
txt = txt.encode('latin1')
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-1:
ordinal not in range(256)
***
but write(..) before write_html(..) doesn't give it :)
pdf.write(8, u'Ąžuolas')
pdf.write_html(u"<font face='DejaVu'>Ąžuolas</font>") # no problem :)
Original comment by jurgis.pralgauskis
on 28 Apr 2013 at 7:56
I could workaround by repeatidly setting font for write
pdf.set_font('DejaVu', '', 14)
pdf.write_html(u"<font face='DejaVu'>Ąžuolas</font>")
pdf.set_font('DejaVu', '', 14)
pdf.write(8, u'Ąžuolas')
Original comment by jurgis.pralgauskis
on 28 Apr 2013 at 7:58
a, I get -- I don't need to pdf.set_font(..) for write_html
as I indicate it in <font ...> tag :)
Original comment by jurgis.pralgauskis
on 28 Apr 2013 at 8:09
by the way, I can give string without u prepended, and works ok (encodings are
mystic :)
pdf.write_html("<font face='DejaVu' size='40'>.. Ąžuolas</font>")
Original comment by jurgis.pralgauskis
on 28 Apr 2013 at 8:17
Thanks for reporting and testing the solution!
Original comment by reingart@gmail.com
on 5 Feb 2014 at 1:47
Original issue reported on code.google.com by
jurgis.pralgauskis
on 26 Apr 2013 at 8:23