also posted issue on pyfpdf site 
http://code.google.com/p/pyfpdf/issues/detail?id=54&thanks=54&ts=1367007819

2013 m. balandis 26 d., penktadienis 23:17:41 UTC+3, Jurgis Pralgauskis 
rašė:
>
> 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 
>
> 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"<https://jurgis.pythonanywhere.com/admin/default/edit/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') )
>
> 2013 m. balandis 26 d., penktadienis 22:03:41 UTC+3, Jurgis Pralgauskis 
> rašė:
>>
>> Hi, 
>>
>> but this seems to work not for all unicode characters
>> like if I have "Ąžuolas"
>>
>> u"Ąžuolas".encode('iso-8859-1')   gives error :/
>>
>> UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-1: 
>> ordinal not in range(256)
>>
>>
>> I also posted on hosting forum looking for TTF solution
>>  https://www.pythonanywhere.com/forums/topic/602/#id_post_4362
>>
>> 2011 m. balandis 29 d., penktadienis 06:35:40 UTC+3, Alexandre Andrade 
>> rašė:
>>>
>>> The same can be converted to a function, to make it easier:
>>>
>>> def lt(str):
>>>     return unicode(str,'utf-8').encode('iso-8859-1')
>>>
>>>
>>> so just 
>>>
>>> pdf.cell(50,20,lt('Helló Wórld'), 0,2,'L') 
>>>
>>> 2011/4/29 Christopher Steel <chris...@gmail.com>
>>>
>>>>
>>>> This solution works well. You will need to make a minor correction and
>>>> remove the single quotes around 'txt' in the second line. The edited
>>>> version looks like this:
>>>>
>>>>    txt = 'Hélló wórld'
>>>>    utxt = unicode(txt, 'utf-8')
>>>>    stxt = utxt.encode('iso-8859-1')
>>>>    pdf.cell(50,20, stxt, 0, 2, 'L')
>>>>
>>>>
>>>> Thanks for the hint Bernardo!
>>>>
>>>> C.
>>>>
>>>>
>>>> ---------- Forwarded message ----------
>>>> From: Bernardo <estem...@gmail.com>
>>>> Date: Sep 25 2010, 7:35 am
>>>> Subject: Solved -- Problems with special characters and pyfpdf
>>>> To: web2py-users
>>>>
>>>>
>>>> Hi all,
>>>>
>>>> When usingpyfpdfwhich comes with web2py framework, there are some
>>>> issues withspecialcharacterssuch as accentedcharacters(á, é,
>>>> í, ...). After some research, I found out thatpyfpdfjust understands
>>>> 'iso-8859-1', and web2py gives him the strings in 'utf-8' format.
>>>>
>>>> So, as a solution, in your python code you just have to convert the
>>>> string before passing it topyfpdf, like this:
>>>>
>>>> txt = 'Hélló wórld'
>>>> utxt = unicode('txt', 'utf-8')
>>>> stxt = utxt.encode('iso-8859-1')
>>>> pdf.cell(50,20, stxt, 0, 2, 'L')
>>>>
>>>> If anyone has any doubts, just ask. I hope this can help someone...
>>>>
>>>> kind regards,
>>>> Bernardo
>>>>
>>>
>>>
>>>
>>> -- 
>>> Atenciosamente
>>>
>>>
>>> Alexandre Andrade
>>> Hipercenter.com Classificados Gratuitos
>>>  
>>

-- 

--- 
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.


Reply via email to