Hi Mic! This is very interesting! :) how does it work? you have "URL('gen_pdf')", what is that referencing?
would you have a model/sample app that we could peek at? :) Thanks, Mart :) On Aug 15, 4:47 pm, Michele Comitini <michele.comit...@gmail.com> wrote: > Suppose you want to make an AJAX call that starts a file download. > How can you do that? > 1. form submission > 2. a element href > 3. iframe > > 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