Thank you, I have tried u"World äöü éè €" and "World äöü éè €"
and both table =TAG.font(table, _face="DejaVu") html = str(XML(table, sanitize=False)) pdf.write_html(html) and html = str(XML(table, sanitize=False)) html="<font face='DejaVu'>%s</font>" % html pdf.write_html(html) The result is the same html-string No success - the pdf file remains unchanged. It looks like Times Roman and not Sans serif. Has anybody tried my whole example with success? Regards, Martin 2013/5/2 Jurgis Pralgauskis <jurgis.pralgaus...@gmail.com> > by the way, not sure, if there is need to write > u"World äöü éè €" > or just "World äöü éè €" > > seems, both work > > > On Thu, May 2, 2013 at 3:00 PM, Martin Weissenboeck <mweis...@gmail.com>wrote: > >> Some hours later... >> Now I have tried to use the Arial-font: >> >> pdf.set_font('Arial','',10) >> >> There is always the same font - set_font seems to do nothing. >> >> >> >> >> >> 2013/5/2 Martin Weissenboeck <mweis...@gmail.com> >> >>> Hi, >>> I have tried again to generate a pdf file from an htlm file with >>> someunicode characters. >>> There is my test program. It's a simplified version, in the original >>> program there is a lot of additional test lines. >>> >>> def pp(): >>> from gluon.contrib.pyfpdf import FPDF, HTMLMixin >>> >>> class MyFPDF(FPDF, HTMLMixin): >>> def header(self): pass >>> def footer(self): pass >>> >>> # create a small table with some data: >>> rows = [THEAD(TR(TH("Key",_width="70%"), TH("Value",_width="30%"))), >>> TBODY(TR(TD("Hello"),TD("60")), >>> TR(TD("World äöü éè €"),TD("40")))] >>> table = TABLE(*rows, _border="0", _align="center", _width="50%") >>> >>> pdf=MyFPDF() >>> >>> pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', uni=True) >>> pdf.add_page() >>> pdf.set_font('DejaVu','',10) # set font method 1 >>> # table =TAG.font(table, _face="DejaVu") # set font method 2 >>> html = str(XML(table, sanitize=False)) >>> pdf.write_html(html) >>> response.headers['Content-Type'] = "application/pdf" >>> return pdf.output(dest='S') >>> >>> I am sure that the font file is loaded, but it seems that the font is >>> not used. >>> I have tried two methods to change the font, but the results are the >>> same. >>> It doesn't look like Sanserif and every Unicode-Character is printed >>> with every single utf-8 byte. Maybe it's only a small error, but I could >>> not find it. >>> >>> >>> Regards, Martin[image: Inline-Bild 3] >>> >>> >>> 2013/4/30 Jurgis Pralgauskis <jurgis.pralgaus...@gmail.com> >>> >>>> > Which font do you want to include? >>>> >>>> DejaVu - I guess it covers western languages.. (could be withouth >>>> bold/italics to save space) >>>> Another one could be for eastern chars (buy I don't know anything about >>>> them...) >>>> >>>> > I gave you contributor access >>>> >>>> Thanks :) >>>> >>>> >>>> On Wed, May 1, 2013 at 12:22 AM, Mariano Reingart >>>> <reing...@gmail.com>wrote: >>>> >>>>> Which font do you want to include? >>>>> >>>>> The font pack is 15MB, I don't know if it could be included with >>>>> web2py. >>>>> Also, the problem is that no one is complete (you need several fonts >>>>> to cover west / east languages) >>>>> >>>>> https://pyfpdf.googlecode.com/files/fpdf_unicode_font_pack.zip >>>>> >>>>> BTW, thanks for you comments, I gave you contributor access, so you >>>>> can change the docs directly in the wiki if you like so: >>>>> >>>>> https://code.google.com/p/pyfpdf/w/list >>>>> >>>>> If you have any patch, also I'll be happy to review and include it ;-) >>>>> >>>>> Best regards, >>>>> >>>>> Mariano Reingart >>>>> http://www.sistemasagiles.com.ar >>>>> http://reingart.blogspot.com >>>>> >>>>> >>>>> On Sun, Apr 28, 2013 at 7:40 AM, Jurgis Pralgauskis >>>>> <jurgis.pralgaus...@gmail.com> wrote: >>>>> > by the way -- would it be possible to pack at least one ttf with >>>>> web2py, >>>>> > and in normalize_text , when it notices unicode, >>>>> > automatically add (and set) default ttf font (if such is not set) to >>>>> render >>>>> > ok ? >>>>> > >>>>> > >>>>> > >>>>> > On Sun, Apr 28, 2013 at 12:18 PM, Jurgis Pralgauskis >>>>> > <jurgis.pralgaus...@gmail.com> wrote: >>>>> >> >>>>> >> SOLVED - the problem was that I needed to reload web2py -- for >>>>> changed >>>>> >> html.py to make effect ;) >>>>> >> >>>>> >> one more issue >>>>> >> that after write_html(..) it "forgets" the previously set font >>>>> (should >>>>> >> be at least mentioned in docs.. :) >>>>> >> https://code.google.com/p/pyfpdf/issues/detail?id=54#c2 >>>>> >> >>>>> >> >>>>> >> >>>>> >> >>>>> >> On Sat, Apr 27, 2013 at 9:06 PM, Mariano Reingart < >>>>> reing...@gmail.com> >>>>> >> wrote: >>>>> >>> >>>>> >>> Did you add the TTF unicode font with add_font? >>>>> >>> Can you post a complete example (ie a script.py just with the code >>>>> to >>>>> >>> test), so I can reproduce it easily. >>>>> >>> >>>>> >>> Best regards, >>>>> >>> >>>>> >>> Mariano Reingart >>>>> >>> http://www.sistemasagiles.com.ar >>>>> >>> http://reingart.blogspot.com >>>>> >>> >>>>> >>> >>>>> >>> On Sat, Apr 27, 2013 at 7:30 AM, Jurgis Pralgauskis >>>>> >>> <jurgis.pralgaus...@gmail.com> wrote: >>>>> >>> > I see 2 lines were changed, the main >>>>> >>> > >>>>> >>> > - if 'face' in attrs and attrs['face'].lower() in self.font_list: >>>>> >>> > + if 'face' in attrs: >>>>> >>> > >>>>> >>> > but I still get >>>>> >>> > >>>>> >>> > >>>>> >>> > File >>>>> >>> > >>>>> "/home/jurgis/web2py/applications/apskaitele/controllers/default.py", >>>>> >>> > line 61, in pdftest >>>>> >>> > >>>>> >>> > >>>>> >>> > pdf.write_html(u"<font face='DejaVu'>Ąžuolas</font>" >>>>> >>> > ) >>>>> >>> > >>>>> >>> > >>>>> >>> > File "/home/jurgis/web2py/gluon/contrib/fpdf/html.py", line 397, >>>>> in >>>>> >>> > write_html >>>>> >>> > >>>>> >>> > File "/usr/local/lib/python2.7/HTMLParser.py", line 114, in >>>>> feed >>>>> >>> > >>>>> >>> > self.goahead(0) >>>>> >>> > File "/usr/local/lib/python2.7/HTMLParser.py", line 152, in >>>>> goahead >>>>> >>> > >>>>> >>> > if i < j: self.handle_data(rawdata[i:j]) >>>>> >>> > >>>>> >>> > File "/home/jurgis/web2py/gluon/contrib/fpdf/html.py", line >>>>> 122, in >>>>> >>> > handle_data >>>>> >>> > >>>>> >>> > File "/home/jurgis/web2py/gluon/contrib/fpdf/fpdf.py", line >>>>> 822, in >>>>> >>> > write >>>>> >>> > >>>>> >>> > txt = self.normalize_text(txt) >>>>> >>> > >>>>> >>> > File "/home/jurgis/web2py/gluon/contrib/fpdf/fpdf.py", line >>>>> 1012, in >>>>> >>> > normalize_text >>>>> >>> > >>>>> >>> > txt = txt.encode('latin1') >>>>> >>> > >>>>> >>> > UnicodeEncodeError: 'latin-1' codec can't encode characters in >>>>> position >>>>> >>> > 0-1: >>>>> >>> > ordinal not in range(256 >>>>> >>> > ) >>>>> >>> > >>>>> >>> > >>>>> >>> > >>>>> >>> > and if I >>>>> >>> > pdf.write_html(u"<font >>>>> face='DejaVu'>Ąžuolas</font>".encode('utf8')) >>>>> >>> > >>>>> >>> > I get Ä„Å3⁄4uolas >>>>> >>> > >>>>> >>> > >>>>> >>> > >>>>> >>> > >>>>> >>> > On Sat, Apr 27, 2013 at 3:24 AM, Mariano Reingart < >>>>> reing...@gmail.com> >>>>> >>> > wrote: >>>>> >>> >> >>>>> >>> >> Sorry, I misread the email. >>>>> >>> >> >>>>> >>> >> Unicode fonts were not supported in html2pdf. >>>>> >>> >> >>>>> >>> >> 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 >>>>> >>> >> >>>>> >>> >> Best regards >>>>> >>> >> Mariano Reingart >>>>> >>> >> http://www.sistemasagiles.com.ar >>>>> >>> >> http://reingart.blogspot.com >>>>> >>> >> >>>>> >>> >> >>>>> >>> >> On Fri, Apr 26, 2013 at 11:45 PM, Mariano Reingart >>>>> >>> >> <reing...@gmail.com> >>>>> >>> >> wrote: >>>>> >>> >> > On Fri, Apr 26, 2013 at 11:42 PM, Mariano Reingart >>>>> >>> >> > <reing...@gmail.com> >>>>> >>> >> > wrote: >>>>> >>> >> >> On Fri, Apr 26, 2013 at 6:34 PM, Jonathan Lundell >>>>> >>> >> >> <jlund...@pobox.com> >>>>> >>> >> >> wrote: >>>>> >>> >> >>> On 26 Apr 2013, at 1:17 PM, Jurgis Pralgauskis >>>>> >>> >> >>> <jurgis.pralgaus...@gmail.com> wrote: >>>>> >>> >> >>> >>>>> >>> >> >>> ok, SOLVED ttf issue for unicode example >>>>> >>> >> >>> http://code.google.com/p/pyfpdf/wiki/Unicode >>>>> >>> >> >>> just needed to create directory gluon > contrib > fpdf > >>>>> font >>>>> >>> >> >>> and place needed ttf files insited it :) >>>>> >>> >> >>> then pdf.write(8, u"Ąžuolas") works fine >>>>> >>> >> >>> >>>>> >>> >> >>> >>>>> >>> >> >>> The fpdf logic uses utf8 for fonts it sees as UTF-based, >>>>> otherwise >>>>> >>> >> >>> latin-1. >>>>> >>> >> >>> It looks to me as though either it isn't recognizing your >>>>> fonts as >>>>> >>> >> >>> UTF, or >>>>> >>> >> >>> there's some overlooked case that it's making a mistake >>>>> with. Have >>>>> >>> >> >>> a >>>>> >>> >> >>> look at >>>>> >>> >> >>> FPDF.set_font: >>>>> >>> >> >>> >>>>> >>> >> >>> self.unifontsubset = (self.fonts[fontkey]['type'] == >>>>> >>> >> >>> 'TTF') >>>>> >>> >> >>> >>>>> >>> >> >>> ...and make sure it's getting set. >>>>> >>> >> >>> >>>>> >>> >> >> >>>>> >>> >> >> Yes, as Jhonatan saids, FPDF (and the PDF standard, BTW) only >>>>> >>> >> >> support >>>>> >>> >> >> latin1 characters for standard font. >>>>> >>> >> >> >>>>> >>> >> >> If you need utf8 characters, you need to embeed a T >>>>> >>> >> > >>>>> >>> >> > You need to embed a UTF8 TTF font, for example: >>>>> >>> >> > >>>>> >>> >> > # Add a DejaVu Unicode font (uses UTF-8) >>>>> >>> >> > # Supports more than 200 languages. For a coverage status see: >>>>> >>> >> > # >>>>> >>> >> > >>>>> >>> >> > >>>>> http://dejavu.svn.sourceforge.net/viewvc/dejavu/trunk/dejavu-fonts/langcover.txt >>>>> >>> >> > pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', >>>>> uni=True) >>>>> >>> >> > >>>>> >>> >> > (sorry, the previous message was sent incomplete) >>>>> >>> >> > >>>>> >>> >> > I'll try to enhance the docs about this, thank for reporting >>>>> the >>>>> >>> >> > issue >>>>> >>> >> > >>>>> >>> >> > Best regards >>>>> >>> >> > >>>>> >>> >> > Mariano Reingart >>>>> >>> >> > http://www.sistemasagiles.com.ar >>>>> >>> >> > http://reingart.blogspot.com >>>>> >>> >> >>>>> >>> >> -- >>>>> >>> >> >>>>> >>> >> --- >>>>> >>> >> You received this message because you are subscribed to a topic >>>>> in the >>>>> >>> >> Google Groups "web2py-users" group. >>>>> >>> >> To unsubscribe from this topic, visit >>>>> >>> >> >>>>> >>> >> >>>>> https://groups.google.com/d/topic/web2py/KJDeQoLKw-M/unsubscribe?hl=en >>>>> . >>>>> >>> >> To unsubscribe from this group and all its topics, send an >>>>> email to >>>>> >>> >> web2py+unsubscr...@googlegroups.com. >>>>> >>> >> >>>>> >>> >> For more options, visit >>>>> https://groups.google.com/groups/opt_out. >>>>> >>> >> >>>>> >>> >> >>>>> >>> > >>>>> >>> > >>>>> >>> > >>>>> >>> > -- >>>>> >>> > Jurgis Pralgauskis >>>>> >>> > tel: 8-616 77613; >>>>> >>> > Don't worry, be happy and make things better ;) >>>>> >>> > http://galvosukykla.lt >>>>> >>> > >>>>> >>> > -- >>>>> >>> > >>>>> >>> > --- >>>>> >>> > You received this message because you are subscribed to the >>>>> Google >>>>> >>> > Groups >>>>> >>> > "web2py-users" group. >>>>> >>> > To unsubscribe from this group and stop receiving emails from >>>>> it, send >>>>> >>> > an >>>>> >>> > email to web2py+unsubscr...@googlegroups.com. >>>>> >>> > For more options, visit https://groups.google.com/groups/opt_out >>>>> . >>>>> >>> > >>>>> >>> > >>>>> >>> >>>>> >>> -- >>>>> >>> >>>>> >>> --- >>>>> >>> You received this message because you are subscribed to a topic in >>>>> the >>>>> >>> Google Groups "web2py-users" group. >>>>> >>> To unsubscribe from this topic, visit >>>>> >>> >>>>> https://groups.google.com/d/topic/web2py/KJDeQoLKw-M/unsubscribe?hl=en >>>>> . >>>>> >>> To unsubscribe from this group and all its topics, send an email to >>>>> >>> web2py+unsubscr...@googlegroups.com. >>>>> >>> For more options, visit https://groups.google.com/groups/opt_out. >>>>> >>> >>>>> >>> >>>>> >> >>>>> >> >>>>> >> >>>>> >> -- >>>>> >> Jurgis Pralgauskis >>>>> >> tel: 8-616 77613; >>>>> >> Don't worry, be happy and make things better ;) >>>>> >> http://galvosukykla.lt >>>>> > >>>>> > >>>>> > >>>>> > >>>>> > -- >>>>> > Jurgis Pralgauskis >>>>> > tel: 8-616 77613; >>>>> > Don't worry, be happy and make things better ;) >>>>> > http://galvosukykla.lt >>>>> > >>>>> > -- >>>>> > >>>>> > --- >>>>> > You received this message because you are subscribed to the Google >>>>> Groups >>>>> > "web2py-users" group. >>>>> > To unsubscribe from this group and stop receiving emails from it, >>>>> send an >>>>> > email to web2py+unsubscr...@googlegroups.com. >>>>> > For more options, visit https://groups.google.com/groups/opt_out. >>>>> > >>>>> > >>>>> >>>>> -- >>>>> >>>>> --- >>>>> You received this message because you are subscribed to a topic in the >>>>> Google Groups "web2py-users" group. >>>>> To unsubscribe from this topic, visit >>>>> https://groups.google.com/d/topic/web2py/KJDeQoLKw-M/unsubscribe?hl=en >>>>> . >>>>> To unsubscribe from this group and all its topics, send an email to >>>>> web2py+unsubscr...@googlegroups.com. >>>>> For more options, visit https://groups.google.com/groups/opt_out. >>>>> >>>>> >>>>> >>>> >>>> >>>> -- >>>> Jurgis Pralgauskis >>>> tel: 8-616 77613; >>>> Don't worry, be happy and make things better ;) >>>> http://galvosukykla.lt >>>> >>>> -- >>>> >>>> >>> >> -- >> >> --- >> You received this message because you are subscribed to a topic in the >> Google Groups "web2py-users" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/web2py/KJDeQoLKw-M/unsubscribe?hl=en. >> To unsubscribe from this group and all its topics, send an email to >> web2py+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > > > -- > Jurgis Pralgauskis > tel: 8-616 77613; > Don't worry, be happy and make things better ;) > http://galvosukykla.lt > > -- > > --- > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to web2py+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
<<image.png>>