# -*- coding: latin-1 -*- "HTML Renderer for FPDF.py" __author__ = "Mariano Reingart " __copyright__ = "Copyright (C) 2010 Mariano Reingart" __license__ = "LGPL 3.0" # Inspired by tuto5.py and several examples from fpdf.org, html2fpdf, etc. from fpdf import FPDF, HTMLMixin if __name__=='__main__': html="""

html2fpdf

Basic usage

You can now easily print text mixing different styles : bold, italic, underlined, or all at once!
You can also insert links on text, such as www.fpdf.org, or on an image: click on the logo.

Sample List

Header 1header 2
cell 1cell 2
cell 2cell 3
""" + """""" * 200 + """
Header 1header 2
footer 1footer 2
cell 1cell 2
cell 1cell 2
cell spanned
cell 3cell 4
cell 5cell 6
Font example: Arial 40pt """ class MyFPDF(FPDF, HTMLMixin): def header(self): self.image('../tutorial/logo_pb.png',10,8,33) self.set_font('Arial','B',15) self.cell(80) self.cell(30,10,'Title',1,0,'C') self.ln(20) def footer(self): self.set_y(-15) self.set_font('Arial','I',8) txt = 'Page %s of %s' % (self.page_no(), self.alias_nb_pages()) self.cell(0,10,txt,0,0,'C') pdf=MyFPDF() #First page pdf.add_page() pdf.write_html(html) # this will fail (tables without widht are not supported): try: pdf.write_html("""
""") except RuntimeError: pass # this may be rendered incorrectly as currently there is no two pass auto-layout: pdf.write_html("""
100%
""") fn = 'html.pdf' pdf.output(fn,'F') import os try: os.startfile(fn) except: os.system("xdg-open \"%s\"" % fn)