Thank you Alexandre, now I am feeling exceptionally lazy as well as
being highly satisfied with the end results and am therefore impelled
to add something (anything!) as well.

If you as lazy as I am, opps, I mean, if you want to keep all of your
pdf related imports and code in a single file(controller) but want to
"hide" the function you can start your conversion function name with
an underscore.

In addition the following "laziness enhanced' version of Alexandre's
function also uses an "explicit" version of 'cell' for folks who are
too lazy to memorize this http://code.google.com/p/pyfpdf/wiki/Cell ,
I mean, umm, for folks who would like to see an example using a more
explicit cell definition methods...

def _i2u(str):
    '''
    convert iso-8859-1
    '''
    return unicode(str,'utf-8').encode('iso-8859-1')

pdf.cell(w=97.5,h=9,txt=_i2u('Montréal
2011'),border='',ln=1,align='R',fill=0,link='')


; )

Chris

On 28 avr, 23:35, Alexandre Andrade <alexandrema...@gmail.com> wrote:
> 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.st...@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

Reply via email to