Please, can you attach a minimal script to reproduce this?

You should pass unicodes when using utf8, do not pass strings with
.encode('utf8')
(using utf8 fonts you can avoid the if isinstance(text, unicode):
block completely)

Yes unicode python support is hard to master, luckily in py3k it is a bit easier

Best regards,

Mariano Reingart
http://www.sistemasagiles.com.ar
http://reingart.blogspot.com


On Sat, Apr 27, 2013 at 12:37 AM, Jurgis Pralgauskis
<[email protected]> wrote:
> Hi,
>
> I tried to combine ideas from http://code.google.com/p/pyfpdf/wiki/Templates
> and http://code.google.com/p/pyfpdf/wiki/Unicode
>
> but not much luck... encodings were always hard for me...
>
> I can insert unicode via direct "write" ok,
>
> but if I try to insert it via cell/multicell, I get stuck ...
>
> I changed file encoding of template.py
> and also replaced
>         if isinstance(text, unicode):
>             #~ text = text.encode("latin1","ignore")
>             text = text.encode('utf8')
>
> and explicitly changed all set_font to:
>             #~ pdf.set_font(font,style,size)
>             pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', uni=True)
>             pdf.set_font('DejaVu','',size)
>
> but then I get:
>
> Traceback (most recent call last):
>   File "unicode_template.py", line 321, in <module>
>     f.render("./invoice.pdf")
>   File "unicode_template.py", line 135, in render
>     self.handlers[element['type'].upper()](pdf, **element)
>   File "unicode_template.py", line 172, in text
>     pdf.cell(w=x2-x1,h=y2-y1,txt=text,border=0,ln=0,align=align)
>   File "/home/nijole/Downloads/pyfpdf/fpdf/fpdf.py", line 632, in cell
>     txt = self.normalize_text(txt)
>   File "/home/nijole/Downloads/pyfpdf/fpdf/fpdf.py", line 1043, in
> normalize_text
>     txt = txt.decode('utf8')
>   File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
>     return codecs.utf_8_decode(input, errors, True)
> UnicodeDecodeError: 'utf8' codec can't decode byte 0xba in position 1:
> invalid start byte
>
> --
>
> ---
> 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.
>
>

-- 

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