Project 14: PDF Certificate Maker 📜¶

Difficulty: 🟡 Intermediate

Run cells top to bottom. Each step builds on the previous one and saves real files under outputs/pdf_certificate_maker/.

← Back to index

Description¶

Generate a printable achievement certificate PDF — perfect for workshops, courses, or fun awards.

Libraries & Modules¶

  • fpdf (fpdf2) — FPDF
  • Built-in: datetime

Python Concepts You'll Practice¶

PDF layout, fonts, coordinates, text positioning

🎛️ Parameter Variations¶

  • RECIPIENT_NAME, COURSE_TITLE, INSTRUCTOR
  • ACCENT_COLOR — RGB tuple for borders
  • ORIENTATION — 'P' portrait vs 'L' landscape
In [1]:
# Install dependencies for this project (safe to re-run)
import sys
!{sys.executable} -m pip install pillow numpy matplotlib wordcloud qrcode[pil] python-barcode fpdf2 jinja2 folium plotly pandas scipy ipywidgets -q
Skipping pip install (already installed)
In [2]:
# Interactive Jupyter setup — run this cell first
%matplotlib inline

from pathlib import Path
from IPython.display import display, Image as IPImage, HTML, Markdown, Audio, IFrame

OUTPUT_DIR = Path("outputs") / "pdf_certificate_maker"
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
print(f"✅ Outputs folder: {OUTPUT_DIR.resolve()}")
✅ Outputs folder: C:\Users\Hansel Yan\Projects\CodeItAll\outputs\pdf_certificate_maker

Step 1 — Design and render certificate¶

In [3]:
from fpdf import FPDF
from datetime import date

# 🎛️ TWEAK THESE
RECIPIENT_NAME = "Alex Chen"
COURSE_TITLE = "Python Foundations - CodeItAll"
INSTRUCTOR = "CodeItAll Academy"
ACCENT_COLOR = (108, 92, 231)  # RGB purple
ORIENTATION = "L"  # Landscape
DATE_STR = date.today().strftime("%B %d, %Y")

class Certificate(FPDF):
    def header(self):
        pass

pdf = Certificate(orientation=ORIENTATION, unit="mm", format="A4")
pdf.add_page()
pdf.set_fill_color(*ACCENT_COLOR)

# Border
pdf.set_line_width(2)
pdf.rect(10, 10, 277, 190)

# Title
pdf.set_font("Helvetica", "B", 36)
pdf.set_text_color(*ACCENT_COLOR)
pdf.ln(40)
pdf.cell(0, 20, "Certificate of Achievement", align="C", ln=True)

pdf.set_font("Helvetica", "", 16)
pdf.set_text_color(60, 60, 60)
pdf.ln(10)
pdf.cell(0, 10, "This certifies that", align="C", ln=True)

pdf.set_font("Helvetica", "B", 28)
pdf.set_text_color(30, 30, 30)
pdf.ln(5)
pdf.cell(0, 15, RECIPIENT_NAME, align="C", ln=True)

pdf.set_font("Helvetica", "", 14)
pdf.set_text_color(80, 80, 80)
pdf.ln(8)
pdf.cell(0, 10, f"has successfully completed", align="C", ln=True)
pdf.set_font("Helvetica", "BI", 18)
pdf.cell(0, 12, COURSE_TITLE, align="C", ln=True)

pdf.ln(20)
pdf.set_font("Helvetica", "", 12)
pdf.cell(0, 8, f"Instructor: {INSTRUCTOR}  |  Date: {DATE_STR}", align="C")

out = OUTPUT_DIR / "certificate.pdf"
pdf.output(str(out))
print(f"Certificate saved to {out}")
Certificate saved to outputs\pdf_certificate_maker\certificate.pdf
C:\Users\Hansel Yan\AppData\Local\Temp\ipykernel_30516\2626242169.py:28: DeprecationWarning: The parameter "ln" is deprecated since v2.5.2. Instead of ln=True use new_x=XPos.LMARGIN, new_y=YPos.NEXT.
  pdf.cell(0, 20, "Certificate of Achievement", align="C", ln=True)
C:\Users\Hansel Yan\AppData\Local\Temp\ipykernel_30516\2626242169.py:33: DeprecationWarning: The parameter "ln" is deprecated since v2.5.2. Instead of ln=True use new_x=XPos.LMARGIN, new_y=YPos.NEXT.
  pdf.cell(0, 10, "This certifies that", align="C", ln=True)
C:\Users\Hansel Yan\AppData\Local\Temp\ipykernel_30516\2626242169.py:38: DeprecationWarning: The parameter "ln" is deprecated since v2.5.2. Instead of ln=True use new_x=XPos.LMARGIN, new_y=YPos.NEXT.
  pdf.cell(0, 15, RECIPIENT_NAME, align="C", ln=True)
C:\Users\Hansel Yan\AppData\Local\Temp\ipykernel_30516\2626242169.py:43: DeprecationWarning: The parameter "ln" is deprecated since v2.5.2. Instead of ln=True use new_x=XPos.LMARGIN, new_y=YPos.NEXT.
  pdf.cell(0, 10, f"has successfully completed", align="C", ln=True)
C:\Users\Hansel Yan\AppData\Local\Temp\ipykernel_30516\2626242169.py:45: DeprecationWarning: The parameter "ln" is deprecated since v2.5.2. Instead of ln=True use new_x=XPos.LMARGIN, new_y=YPos.NEXT.
  pdf.cell(0, 12, COURSE_TITLE, align="C", ln=True)

✅ Project complete¶

Check your output folder: outputs/pdf_certificate_maker/

Next: Project 15: Email HTML Renderer · Index