On Sun, Oct 3, 2010 at 1:10 AM, mdipierro <[email protected]> wrote:
>
> I am sure this can also be done and better with pyfpdf but I have not
> tried. Perhaps Mariano can help us

Having latest web2py versions (including pyfpdf), write in a views/generic.pdf:

---- begin file ----
{{

from gluon.contrib.pyfpdf import FPDF, HTMLMixin
from gluon.sanitizer import sanitize

class MyFPDF(FPDF, HTMLMixin):
    pass

pdf=MyFPDF()
pdf.add_page()
html=response.render('%s/%s.html' %
(request.controller,request.function))
html = sanitize(html, escape=False)
pdf.write_html(html)
response.headers['Content-Type']='application/pdf'
response.write(pdf.output(dest='S'), escape=False)

}}
---- end file---

At MyFPDF class you can add headers and footers.

The sanitize part is to strip some HTML tags that cannot be rendered
(ie. javascript).

As some DIVs contents and similar may still pass (like menus), a
better alternative may be render only certains portions of the page in
a custom view:

pdf.write_html(str(XML(CENTER(section), sanitize=False)))

Best regards,

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

Reply via email to