Too complex!
of course *web2py* comes to rescue...
BIG NOTE: the following is based on 'data:' url type and was tested
only on FF and chrome. I do not have
IE but I suppose that is not compatible with the standard!
In your view put a web2py ajax call similar to the following wherever
you need it:
ajax('%s',[],':eval');" % URL('gen_pdf')
ex.
{{=A(T('be brave!'), _onclick="ajax('%s',[],':eval');" %
URL('gen_pdf'), _class='button')}}
in the controller use embed64.
def gen_pdf():
from gluon.contrib.pyfpdf import FPDF
pdf=FPDF()
pdf.add_page()
pdf.set_font('Arial','B',16)
pdf.cell(40,10,'Hello World at %s!' % request.now)
doc=pdf.output(dest='S')
doc64=embed64(data=doc,extension='application/pdf')
return 'window.location="%s";' % doc64
have fun!
mic
Copy sample code in my previous mail.
to test quicly you cat put the view code somewhere in
/welcome/views/default/index.html
{{=A(T('be brave!'), _onclick="ajax('%s',[],':eval');" %
URL('gen_pdf'), _class='button')}}
copy the function gen_pdf() in /welcome/controllers/default.py
def gen_pdf():
from gluon.contrib.pyfpdf import FPDF
pdf=FPDF()
pdf.add_page()
pdf.set_font('Arial','B',16)
pdf.cell(40,10,'Hello World at %s!' % request.now)
doc=pdf.output(dest='S')
doc64=embed64(data=doc,extension='application/pdf')
return 'window.location="%s";' % doc64
No need for other code. The trick is all in the use of 'data:' URI
that is created by embed64()
ok now URL('gen_pdf()') calls gen_pdf() in the controller that
generates the pdf on the fly and posts it back to the browser.
All in one pass, no session no temporary files around, no form, no GET...
;-)
mic
2011/8/16 mart <msene...@gmail.com>: