Martin:

I've updated the web2py fpdf example addressing your issues (described bellow):

http://pyfpdf.googlecode.com/files/web2py.app.fpdf_20130218.w2p

(2) About unicode support, You need to pass unicode strings: u"my
unicode string" (look at the u prefix).
Also, you need embed a ttf unicode fonts (normal pdf fonts doesn't
include support beyond latin1, so there is an additional font pack in
downloads)
Please see:

https://code.google.com/p/pyfpdf/wiki/Unicode

Here is the example adapted for unicode

def get_me_a_unicode_pyfpdf():
    title = "This The Doc Title"
    heading = "First Paragraph"

    # to use unicode, add the u"" (and ensure your source code and
text is in utf-8)
    text = u"blä€ß " * 10000

    pdf=FPDF()

    # load a true-type font that support unicode, like DejaVu:
    # download and unzip
https://pyfpdf.googlecode.com/files/fpdf_unicode_font_pack.zip in the
private folder

    pdf.add_font('DejaVu', '', os.path.join(request.folder, "private",
"font", 'DejaVuSans.ttf'), uni=True)
    pdf.add_font('DejaVu', 'B', os.path.join(request.folder,
"private", "font", 'DejaVuSans-Bold.ttf'), uni=True)
    pdf.add_page()
    pdf.set_font('DejaVu','B',15)
    pdf.cell(w=210,h=9,txt=title,border=0,ln=1,align='C',fill=0)
    pdf.set_font('DejaVu','B',15)
    pdf.cell(w=0,h=6,txt=heading,border=0,ln=1,align='L',fill=0)
    pdf.set_font('DejaVu','',12)
    pdf.multi_cell(w=0,h=5,txt=text)
    response.headers['Content-Type']='application/pdf'
    return pdf.output(dest='S')

(3) If you want the html view, please add

response.view = "generic.html"

Anyway, you need to get the pdf view:

http://localhost:8000/pyfpdf/default/report.pdf

(4) again, unicode... see (2)

(5) this will fail with newer versions of web2py as pdf
tutorial/samples are not included.
You'll need to grab a copy of logo_nb.png from the pypdf package and
change the line whereit uses the image:

logo=os.path.join(request.folder, "private","logo_pb.png")
self.image(logo,10,8,33)

(6) again, add a default view to see the html:

response.view = "generic.html"


(8) idem (5), you need to get the invoice.csv from the pypdf project site

(9) Maybe you are using a older version of web2py, I think Massimo
re-introduced .copy(), but you can take a workaround:

https://code.google.com/p/web2py/issues/detail?id=1255&can=1&q=fpdf

Just replace  element = element.copy() with  element = dict(element)
on template.py, or better, convert rows to dicts in your app:

    # read elements from db
    elements = 
db(db.pdf_element.pdf_template_id==1).select(orderby=db.pdf_element.priority)

    # convert rows to dicts due a web2py internal change (see issue 1255)
    # this prevents AttributeError('Row' object has no attribute 'copy')
    elements = [element.as_dict() for element in elements]

PS: I'm not the creator of this library (it is a port of a well-known
PHP extension and similar libraries).
I'm just the continuator (maintainer), and there are some new
contributors too ;-)

Best regards,

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


On Mon, Feb 18, 2013 at 2:51 AM, Martin Weissenboeck <mweis...@gmail.com> wrote:
> ok, I'll do it.
>
>
> 2013/2/18 Massimo Di Pierro <massimo.dipie...@gmail.com>
>>
>> Bring it up with Mariano, author of fpdf. ;-)
>>
>>
>> On Sunday, 17 February 2013 14:37:03 UTC-6, mweissen wrote:
>>>
>>> I have tried it now. These are my results:
>>>
>>> (1) A text like
>>>
>>>             English: Hello World
>>>             Greek: Γειά σου κόσμος
>>>             Polish: Witaj świecie
>>>             Portuguese: Olá mundo
>>>             Russian: Здравствуй, Мир
>>>             Vietnamese: Xin chào thế giới
>>>             Arabic: مرحبا العالم
>>>             Hebrew:  שלום עולם
>>>
>>> will be converted to pdf.
>>>
>>> (2) But there are problems with right-to-left scripts:
>>> שלום עולם    is written as  םלוע םולש
>>> مرحبا العالم   is written as ملاعلا ابحرم
>>>
>>> (3) pdf.write_html seems to work only with latin-1
>>> pdf.write_html("äöü") is written as "äöü", but
>>> pdf.write_html("äöü".decode('utf-8').encode('latin-1') gives "äöü" - as
>>> expected.
>>>
>>> (4) pdf.write_html does not work with any "&...;" html-character
>>> pdf.write_html("&#62;") gives "#62;"
>>>
>>>
>>> Maybe something should be improved...
>>> Regards, Martin
>>>
>>>
>>>
>>> 2013/2/17 Massimo Di Pierro <massimo....@gmail.com>
>>>>
>>>> I just upgraded to the latest pfdf version (had to make a change for
>>>> compatibility). Please check it.
>>>>
>>>>
>>>> On Sunday, 17 February 2013 11:13:46 UTC-6, mweissen wrote:
>>>>>
>>>>> I want to use the utf-8 character set together with pyfpdf.
>>>>> On https://code.google.com/p/pyfpdf/wiki/Unicode there is pyfpdf
>>>>> version 1.7, which supports utf-8.
>>>>> But in web2py (2.3.2) in gluon\contrib\pyfpdf  fpdf.py is version 1.54b
>>>>>
>>>>> Is there any reason not to use pyfpdf 1.7 in web2py?
>>>>>
>>>>> Regards, Martin
>>>>>
>>>>>
>>>>>
>>>> --
>>>>
>>>> ---
>>>> 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+un...@googlegroups.com.
>>>>
>>>> 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 web2py+unsubscr...@googlegroups.com.
> 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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to