# -*- coding: utf-8 -*- "HTML Renderer for FPDF.py (unicode)" __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__': class MyFPDF(FPDF, HTMLMixin): pass pdf=MyFPDF() # load the unicode font pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', uni=True) pdf.add_page() # test the basic fonts pdf.write_html("""

hello world

""") pdf.write_html("""

hello world

""") pdf.write_html("""

hello world

""") pdf.write_html("""

hello world

""") # test the unicode (utf8) font: # greek pdf.write_html(u"""

Γειά σου κόσμος

""") # russian pdf.write_html(u"""

Здравствуй, Мир

""") fn = 'html_unicode.pdf' pdf.output(fn,'F') import os try: os.startfile(fn) except: os.system("xdg-open \"%s\"" % fn)