On 26 Apr 2013, at 1:17 PM, Jurgis Pralgauskis <[email protected]> 
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.


> 
> BUT - how to make it work with     write_html(...) ?
> 
> write_html( str(P( u"Ąžuolas" ))  #  produces "Ąžuolas"  
> 
> pdf.write_html( u'Ąžuolas'.encode('utf8') )  # also  "Ąžuolas"  
> 
> pdf.write_html( u'Ąžuolas' )   gives error
> 
>   File "/home/jurgis/web2py/applications/apskaitele/controllers/default.py", 
> line 59, in pdftest
>     pdf.write_html( u'Ąžuolas' )
>   File "/home/jurgis/web2py/gluon/contrib/fpdf/html.py", line 397, in 
> write_html
>     h2p.feed(text)
>   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
>     self.pdf.write(self.h,txt)
>   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)
> 
> pdf.write_html( u'Ąžuolas'.decode('utf8') )
> 


-- 

--- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to