def pyfpdf_from_html(html):
    request = current.request

    def image_map(path):
        if path.startswith('/%s/static/' % request.application):
            return os.path.join(request.folder, path.split('/', 2)[2])
        return 'http%s://%s%s' % (request.is_https and 's' or '', request.env.http_host, path)

    class MyFPDF(FPDF, HTMLMixin):
        pass
    pdf = MyFPDF()
    pdf.add_page()
    html = sanitize(
        html, escape=False)  # should have better list of allowed tags
    pdf.write_html(html, image_map=image_map)
    return XML(pdf.output(dest='S'))
dataset/ETHPy150Open uwdata/termite-data-server/web2py/gluon/contrib/generics.py/pyfpdf_from_html/original