Skip to content

Open In Colab

Open In nbviewer

Hello World with fpdf2

This Jupyter notebook demontrates some basic usage of the Python fpdf2 library

# Installation avec PIP de fpdf2:
!pip install fpdf2

# Enable deprecation warnings:
import warnings
warnings.simplefilter('default', DeprecationWarning)
# Generate a PDF:
from fpdf import FPDF
pdf = FPDF()
pdf.set_font('helvetica', size=48)
pdf.cell(txt="hello world")
pdf_bytes = pdf.output()
# Display the PDF in the notebook by embedding it as HTML content:
WIDTH, HEIGHT = 800, 400 
from base64 import b64encode
from IPython.display import display, HTML
base64_pdf = b64encode(pdf_bytes).decode("utf-8")
display(HTML(f'<embed src="data:application/pdf;base64,{base64_pdf}" width="{WIDTH}" height="{HEIGHT}" type="application/pdf">'))
# Diplay a download button:
display(HTML(f'<a download="fpdf2-demo.pdf" href="data:application/pdf;base64,{base64_pdf}">Click to download PDF</a>'))

To continue learning about fpdf2, check our tutorial: - English - Deutsch - español - हिंदी - português - Русский - Italian - français - Ελληνικά - עברית