Very easy using pisa. You also need to install reportlab and html5lib
but once these have been installed it is simple:

        # to directly get the html for a view
        html = response.render("myview.html", locals())

        filename = "C://outputpdf.pdf"
        f = file(filename, "wb")
        pdf = pisa.CreatePDF(html, f)
        f.close()
        if not pdf.err:
            pisa.startViewer(filename)

The only thing is I found there was actually a pdf generator included
with web2py called pyfpdf. I was all set to replace pisa with this but
now it seems to have disappeared from the book and I can find no
mention of it. Would be useful to have a pdf generator included in the
box with web2py - why was it removed?

On Oct 24, 8:44 am, annet <[email protected]> wrote:
> I am working on a timetable function:
>
> Controller:
>
> def classtimesweek():
>
> rows=db((db.lesrooster.bedrijf_id==1)&(db.lesrooster.dag_id==db.dag.id)&(db 
> .lesrooster.level_id==db.level.id))
> \
>         
> .select(db.lesrooster.ALL,db.dag.dag,db.level.level,orderby=db.lesrooster.d 
> ag_id|
> db.lesrooster.tijd)
>     return dict(rows=rows)
>
> View:
>
> <table id="init" class="display" style="margin-top: 12px;">
>   <thead>
>     ...
>   </thead>
>   <tbody>
>     ...
>   </tbody>
> </table>
>
> Now I would like the user to be able to download the timetable as a
> pdf and print it. What is the most straightforward way to do this?
>
> Kind regards,
>
> Annet.

Reply via email to