Skip to content


fpdf2 supports basic rendering from HTML.

This is implemented by using html.parser.HTMLParser from the Python standard library. The whole HTML 5 specification is very likely not supported, neither as CSS, but bug reports & contributions are very welcome to improve this.

write_html usage example

HTML rendering require the use of fpdf.HTMLMixin, that provides a new write_html method:

from fpdf import FPDF, HTMLMixin

class PDF(FPDF, HTMLMixin):

pdf = PDF()
  <h1>Big title</h1>
    <h2>Section title</h2>
    <p><b>Hello</b> world. <u>I am</u> <i>tired</i>.</p>
    <p><a href="">PyFPDF/fpdf2 GitHub repo</a></p>
    <p align="right">right aligned text</p>
    <p>i am a paragraph <br />in two parts.</p>
    <font color="#00ff00"><p>hello in green</p></font>
    <font size="7"><p>hello small</p></font>
    <font face="helvetica"><p>hello helvetica</p></font>
    <font face="times"><p>hello times</p></font>
    <h2>Other section title</h2>
    <pre>i am preformatted text.</pre>
    <blockquote>hello blockquote</blockquote>
    <table width="50%">
          <th width="30%">ID</th>
          <th width="70%">Name</th>

Supported HTML features

  • <h1> to <h8>: headings (and align attribute)
  • <p>: paragraphs (and align attribute)
  • <b>, <i>, <u>: bold, italic, underline
  • <font>: (and face, size, color attributes)
  • <center> for aligning
  • <a>: links (and href attribute)
  • <img>: images (and src, width, height attributes)
  • <ol>, <ul>, <li>: ordered, unordered and list items (can be nested)
  • <table>: (and border, width attributes)
    • <thead>: header (opens each page)
    • <tfoot>: footer (closes each page)
    • <tbody>: actual rows
    • <tr>: rows (with bgcolor attribute)
    • <th>: heading cells (with align, bgcolor, width attributes)
    • <td>: cells (with align, bgcolor, width attributes)

Note: tables should have at least a first <th> row with a width attribute.