[pydpdf] ('FPDF' object has no attribute 'write_html')

1,998 views
Skip to first unread message

Mamisoa Andriantafika

unread,
Dec 6, 2016, 4:23:46 PM12/6/16
to web2py-users
Hi,

Here is a simple controller.

def test_fpdf():
   
from gluon.contrib.pyfpdf import FPDF, HTMLMixin
    title
= "This The Doc Title"
    heading
= "First Paragraph"
    text
= 'bla'
   
# create a small table with some data:
    rows_body
= []
   
for data in db(db.person.id > 0).select():
        rows_body
.append([TD(str(data.name)), TD(str(data.age))])
    table
=TABLE(THEAD(TR(TH("Name"), TH("Age"))),*[TR(*rows) for rows in rows_body])
    pdf
=FPDF()
    pdf
.add_page()
    pdf
.write_html(str(XML(table, sanitize=False)))
    response
.headers['Content-Type']='application/pdf'
   
return pdf.output(dest='S')

I get an error:

    <type 'exceptions.AttributeError'>('FPDF' object has no attribute 'write_html')


Any idea why ?

Paolo Valleri

unread,
Dec 7, 2016, 12:49:57 PM12/7/16
to web2py-users
see https://github.com/reingart/pyfpdf/blob/master/docs/reference/write_html.md for a detailed example for using write_html

Paolo

Mamisoa Andriantafika

unread,
Dec 7, 2016, 2:23:06 PM12/7/16
to web2py-users
Thanks!
Reply all
Reply to author
Forward
0 new messages