# https://www.blog.pythonlibrary.org/2018/06/05/creating-pdfs-with-pyfpdf-and-python/ from fpdf import FPDF, HTMLMixin class HTML2PDF(FPDF, HTMLMixin): pass html = '''
This is regular text
You can also bold, italicize or underline ''' pdf = HTML2PDF() pdf.add_page() pdf.write_html(html) # pdf.output('html2pdf.pdf') ########## # pdf = FPDF() # pdf.add_page() pdf.set_font("Arial", size=12) pdf.cell(200, 10, txt="Welcome to Python!", ln=1, align="C") pdf.cell(200, 10, txt="Welcome to Python!", ln=1, align="C") pdf.cell(0, 15, txt="Welcome to Python!", ln=1, align="C") pdf.rect(20, 20, 100, 50) ########### spacing=1 data = [['First Name', 'Last Name', 'email', 'zip'], ['Mike', 'Driscoll', 'mike@somewhere.com', '55555'], ['John', 'Doe', 'jdoe@doe.com', '12345'], ['Nina', 'Ma', 'inane@where.com', '54321'] ] # pdf = FPDF() pdf.set_font("Arial", size=12) # pdf.add_page() col_width = pdf.w / 4.5 row_height = pdf.font_size for row in data: for item in row: pdf.cell(col_width, row_height*spacing, txt=item, border=1) pdf.ln(row_height*spacing) ########### pdf.output("simple_demo.pdf")