On Tue, Feb 19, 2013 at 7:10 AM, Martin Weissenboeck <mweis...@gmail.com> wrote: > Hi Mariano, > > thank you very much for your detailed answer. > > I know, you are not the creator of the library, but I think you do a very > important job. Maybe my question could help others and me to use this > program. > > I have played a little bit more with the examples. > http://pyfpdf.googlecode.com/files/web2py.app.fpdf_20130218.w2p > > The error messages have gone - thank you! > > But I have some more questions / comments. I have made some changes and here > are the result. By the way: I am using the last web2py version from trunk. > > (1) in def get_me_a_pdf(): > line 24: > > text = 'blä€ß Χανιά' * 10000 > > or > > text = u'blä€ß Χανιά' * 10000 > > > The result: the “ά” is not shown > That is interesting, because the accent is important in the Greek language > and it could change the meaning of a word..“ά” is replaced by a black > square. Maybe the reportlab font does not know the Unicode character U+03AC?
Sorry, I cannot help you with reportlab, it is a complex software piece. In fact, that's why I don't use reportlab and decided to go with pyfpdf :-) > (2) in def get_me_a_pyfpdf(): > line 48: > text = "blä€ß Χανιά" * 10000 > Result: “blä€ß Χανιά” > > line 48: > > text = u"blä€ß Χανιά" * 10000 > > > Error: > > <type 'exceptions.UnicodeEncodeError'> 'latin-1' codec can't encode > character u'\u20ac' in position 3: ordinal not in range(256) > > > Ok, I see utf-8 or unicode characters are not allowed. Yes, in pyfpdf, if you don't use a unicode font, non utf8 characters are not allowed. > (3) in def get_me_a_unicode_pyfpdf(): > > line 70: > > text = u"blä€ß Χανιά" * 10000 > > > Perfect, the pdf-file shows “blä€ß Χανιά” Please note that for some languages / characters, you will need special fonts (for example, chinese, thai, etc.) > (4) in def listing(): > > line 142: > response.title = "web2py sample listing with äö€ß Χανιά" > > listing.html is ok > listing.pdf: > > “web2py sample listing with äö€ß Χανιά” > > > I think there is a problem. It seems, that HTML-texts with no-latin-1 > characters (like “äö€ß” or “Χανιά") or HTML-equivants (like “α”) do > not work. Yes, you need to set a unicode font like in get_me_a_unicode_pyfpdf() to get non-latin1 support. It's a bit tricky, you could do the following: # add the font to the pdf document: pdf.add_font('DejaVu', '', os.path.join(request.folder, "private", "font", 'DejaVuSans.ttf'), uni=True) # create the basic html parser: h2p = HTML2FPDF(pdf, image_map) # update the supported font list: h2p.font_list = list(h2p.font_list) + ['DejaVu'] # convert basic html to pdf: h2p.feed(text) Then, in your html text, you have to specify the font tag: <font face="DejaVu"> .... </font> > (5) def invoice(): > > line 290 > f["company_name"] = u"Sample Company Χανιά " > Greek letters disappeared: “Sample Company” > > line 299 > f['customer_name'] = u"Sample Client äöü߀" > > “€” disappered: “Sample Client äöüß” Idem to previous issues, you need to add a explicit ttf font with unicode support Change the font face in import_csv so it is used in pdf_element instead the buil-in latin1 fonts: v['pdf_template_id'] = template_id v['font'] = 'DejaVu' # add this! db.pdf_element.insert(**v) Then, in invoice() set the font: f = Template(format="A4", elements = elements, title="Sample Invoice", author="Sample Company", subject="Sample Customer", keywords="Electronic TAX Invoice") # add this to set the font: f.pdf.add_font('DejaVu', '', os.path.join(request.folder, "private", "font", 'DejaVuSans.ttf'), uni=True) detail = "Lorem ipsum dolor sit amet, consectetur. " * 5 > > (6) Some typos: > > line 90: > > "example to generate a pdf based on basic html (use http:/.../report.pdf > download the pdf)" > > > line 218: > > "example to generate an invoice based on a generic pdf template" > Thanks, could you send me the final file fixed, or fill an issue? (some text are truncated in the email) > > (7) From the example on http://code.google.com/p/pyfpdf/wiki/Unicode > > Arabic: مرحبا العالم > > Hebrew: שלום עולם > > > right-to-left scripts are printed in the wrong direction: > > שלום עולם is written as םלוע םולש > > مرحبا العالم is written as ملاعلا ابحرم > With reportlab how are they printed? As far as I know, pyfpdf outputs the same pdf as the php versions. > I speak neither Arabic nor Hebrew, but it seems wrong to me. Me neither, but if you need to change the direction of the text, you could see: http://stackoverflow.com/questions/12233949/changing-page-direction-to-right-to-left-in-fpdf The advantage of pyfpdf is that we can reuse a lot of scripts made for the php versions ;-) Best Regards, Mariano Reingart http://www.sistemasagiles.com.ar http://reingart.blogspot.com -- --- 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.