Character set

21 views
Skip to first unread message

zusfed

unread,
Jan 10, 2011, 6:27:14 AM1/10/11
to geraldo-users
hello ppl,
i just joined to this group, since i couldnt find a solution to my
prob. (not sure if there is any) perhaps i can find an answer or a
milestone here.

i ve installed geraldo today to my app. it looks pretty nice and
fairly easy to use. however the pdf generated by geraldo doesnt show
international characters.. is there a way to show these utf-8
characters in pdf?
i live in turkey, so almost every description fields on my application
have turkish characters. i googled a bit, searched geraldo docs but no
luck .
sorry for my engrish.

ty in advance.

Danilo Cabello

unread,
Jan 10, 2011, 11:42:12 AM1/10/11
to gerald...@googlegroups.com
Zusfed

On Mon, Jan 10, 2011 at 09:27, zusfed <musaf...@gmail.com> wrote:
> is there a way to show these utf-8
> characters in pdf?
> i live in turkey, so almost every description fields on my application
> have turkish characters. i googled a bit, searched geraldo docs but no
> luck .

I think you will have help here, because geraldo is a brazilian
project and I doubt that Marinho (the maintainer) used something like
latin-1 encoding to print out PDF with non-ASCII characters.

Do you use the prefix 'u' in your unicode strings? Example:

# -*- coding: utf-8 -*-
my_turkish_string = u"porção de coração com lingüiça"

Regards,
--
Danilo Cabello
Bottom-poster maniac.

musa fedakar

unread,
Jan 10, 2011, 5:49:26 PM1/10/11
to gerald...@googlegroups.com
hey, thanks for quick reply.
here s the code part  to generate pdf: ( which is fairly simple cause i just followed the tutorial.)

models.py (corresponding object):

class cihazlar(models.Model):
    sno = models.IntegerField()
    aciklama = models.CharField(max_length=100)
    .
    .
    .

   
    def __unicode__(self):
        return self.aciklama

views.py:

def report_go(request):
    resp = HttpResponse(mimetype='application/pdf')

    xcihaz = cihazlar.objects.filter()
    report = CihazRapor(queryset=xcihaz)
    report.generate_by(PDFGenerator, filename=resp)

    return resp

reports.py:

class CihazRapor(Report):
    title = 'ccc'
    author = 'foo'

    page_size = landscape(A4)
    margin_left = 2*cm
    margin_top = 0.5*cm
    margin_right = 0.5*cm
    margin_bottom = 0.5*cm

    class band_detail(ReportBand):
        height = 0.5*cm
        elements=(
            ObjectValue(attribute_name='id', left=0.5*cm),
            ObjectValue(attribute_name='aciklama', left=3*cm,width=10*cm,get_value=lambda instance: 'desc: ' + (instance.aciklama) ,style={'fontName': 'helvetica', 'fontSize': 8})
            )

just for trying here i replaced "instance.aciklama" with:
  • u"some_turkish_char_here"
  • u'\u0131'
    
  • '\xc4\x9f'
but i still got the same result :

ss.png

here you can see how pdf looks. these black squares are turkish characters. (capital I with a dot above it).
i may provide additional information if needed. thank you again :)
regards.
--zusa.






--
Você está recebendo esta mensagem porque se inscreveu no grupo "geraldo-users" dos Grupos do Google.
Para postar neste grupo, envie um e-mail para gerald...@googlegroups.com.
Para cancelar a inscrição nesse grupo, envie um e-mail para geraldo-user...@googlegroups.com.
Para obter mais opções, visite esse grupo em http://groups.google.com/group/geraldo-users?hl=pt-BR.


ss.png

serviciotdf

unread,
Jan 10, 2011, 6:05:26 PM1/10/11
to gerald...@googlegroups.com
Danilo tell you the response.

You need to insert the path to python and the encode

Try to put in the start of every python file (.py), this:

#!/usr/bin/python 
# -*- coding: utf-8 -*-


In Windows:
#!/usr/bin/python 
# -*- coding: windows-1252 -*-



example:

#!/usr/bin/python 
# -*- coding: utf-8 -*-

class cihazlar(models.Model):
    sno = models.IntegerField()
    aciklama = models.CharField(max_length=100)
  
    def __unicode__(self):
        return self.aciklama

-----

#!/usr/bin/python 
# -*- coding: utf-8 -*-

class CihazRapor(Report):
    title = 'ccc'
    author = 'foo'

    page_size = landscape(A4)
    margin_left = 2*cm
    margin_top = 0.5*cm
    margin_right = 0.5*cm
    margin_bottom = 0.5*cm

    class band_detail(ReportBand):
        height = 0.5*cm
        elements=(
            ObjectValue(attribute_name='id', left=0.5*cm),
            ObjectValue(attribute_name='aciklama', left=3*cm,width=10*cm,get_value=lambda instance: 'desc: ' + (instance.aciklama) ,style={'fontName': 'helvetica', 'fontSize': 8})
            )



Maybe this works

Bye


El 10/01/11 19:49, musa fedakar escribió:

Danilo Cabello

unread,
Jan 10, 2011, 9:03:32 PM1/10/11
to gerald...@googlegroups.com
Musa,

On Mon, Jan 10, 2011 at 20:49, musa fedakar <musaf...@gmail.com> wrote:
>
> ObjectValue(attribute_name='aciklama', left=3*cm,width=10*cm,get_value=lambda instance: 'desc: ' + (instance.aciklama) ,style={'fontName': 'helvetica', 'fontSize': 8})

Try to use the unicode encoding, be sure to have your file in unicode
format too and prefer unicode string to avoid some problems, instead
of:

'descr:' + instance.acicklama

Use:

u'descr: %s' % (instance.acicklama,)

This way you assure to have unicode stuff so geraldo and reportlab
tool can print out the PDF in the right way.

musa fedakar

unread,
Apr 26, 2011, 9:00:39 AM4/26/11
to gerald...@googlegroups.com
hello again ppl :)
logn time no see ..

whatever whatever. i ve finally come to a solution for my problem. here s what i did ( for others still experiencing the same):

i opened geraldo/generators/pdf.py

then ive  added this two lines into prepare_additional_fonts
   pdfmetrics.registerFont(TTFont('sanz','/usr/share/fonts/truetype/freefont/FreeSans.ttf'))
   pdfmetrics.registerFont(TTFont('sanzbold','/usr/share/fonts/truetype/freefont/FreeSansBold.ttf'))

so originally it looks like this..

def prepare_additional_fonts(self):
        """This method loads additional fonts and register them using ReportLab
        PDF metrics package.
       
        Just supports TTF fonts, for a while."""
        pdfmetrics.registerFont(TTFont('sanz','/usr/share/fonts/truetype/freefont/FreeSans.ttf'))
        pdfmetrics.registerFont(TTFont('sanzbold','/usr/share/fonts/truetype/freefont/FreeSansBold.ttf'))
       
if not self.report.additional_fonts:
            return


musa fedakar

unread,
Apr 26, 2011, 9:02:20 AM4/26/11
to gerald...@googlegroups.com
hello again ppl :)
logn time no see ..

whatever whatever. i ve finally come to a solution for my problem. here s what i did ( for others still experiencing the same):

i opened geraldo/generators/pdf.py

then ive  added this two lines into prepare_additional_fonts
   pdfmetrics.registerFont(TTFont('sanz','/usr/share/fonts/truetype/freefont/FreeSans.ttf'))
   pdfmetrics.registerFont(TTFont('sanzbold','/usr/share/fonts/truetype/freefont/FreeSansBold.ttf'))

so originally it looks like this..

def prepare_additional_fonts(self):
        """This method loads additional fonts and register them using ReportLab
        PDF metrics package.
       
        Just supports TTF fonts, for a while."""
        pdfmetrics.registerFont(TTFont('sanz','/usr/share/fonts/truetype/freefont/FreeSans.ttf'))
        pdfmetrics.registerFont(TTFont('sanzbold','/usr/share/fonts/truetype/freefont/FreeSansBold.ttf'))
       
        if not self.report.additional_fonts:
            .
            .
            .


then in reports.py
i set the font like:
style={'fontName': 'sanzbold', 'fontSize': 8}


and voila.
i see all turkish chars.


caois
 
Reply all
Reply to author
Forward
0 new messages