jsPDF Certificate Generator with Custom Script Font — Free Snippet

jsPDF Certificate Generator with Custom Script Font · Tools · Plain HTML, CSS & JS · Live preview

What's included

Features

Custom TTF embedding
addFileToVFS plus addFont with a Google Font.
Graceful font fallback
Times Italic if the font can't load.
Chunked base64 conversion
Avoids call-stack limits on large fonts.
Auto-fitting names
getTextWidth shrinks long names.
Wrapped course titles
splitTextToSize with centre alignment.
Print-accurate layout
Millimetre coordinates on A4 landscape.
Colour themes
Ink and accent RGB sets.
Live PDF preview
The real file rendered with PDF.js.

About this UI Snippet

jsPDF Certificates — Custom Fonts, Fitted Text and Print-Ready Layout

Screenshot of the jsPDF Certificate Generator with Custom Script Font snippet rendered live

Course platforms, workshops and HR tools all eventually need to hand out certificates. Generating them in the browser keeps personal data on the user's device and needs no rendering server. This snippet builds a landscape A4 certificate with jsPDF and previews the actual PDF with PDF.js as you type.

Embedding a custom font

jsPDF ships with 14 standard fonts, none of them script faces. To use another font it must be TrueType (.ttf, not WOFF), converted to base64, added to jsPDF's virtual file system with addFileToVFS, and registered with addFont(file, name, style). After that setFont('GreatVibes', 'normal') works like any built-in font. The TTF is fetched once and reused for every re-render. If the fetch fails, the certificate falls back to Times Italic rather than breaking.

Base64 without blowing the stack

String.fromCharCode.apply with a 450 KB array exceeds the maximum argument count, so the conversion processes the bytes in 32 KB chunks before calling btoa.

Text that always fits

Names vary wildly in length. The generator measures the name with getTextWidth and steps the font size down until it fits the available width, with a minimum size. Long course titles wrap with splitTextToSize and centre with { align: 'center' }.

Layout in millimetres

Every element is positioned in millimetres on a 297 × 210 mm page, so the certificate prints at exactly the size you design. Borders are two rectangles with different line widths, and the seal is two concentric circles with small caps text. setCharSpace spaces out the heading letters — and because align: 'center' ignores that spacing, the heading is centred by hand from its measured width plus the added space.

Themes

Three colour themes change the ink and accent colours, applied through setDrawColor, setFillColor and setTextColor with RGB arrays.

Downloads in sandboxes

Sandboxed iframes block downloads, so the status line tells users to open the demo in its own tab if nothing is saved.

Build with AI

Build, Understand, Optimize, and Extend It With AI

Paste this snippet into an AI assistant like Claude and ask it to explain the steps for embedding a TrueType font in jsPDF. Ask it to add a QR code linking to a verification URL, a logo image, bulk generation from a CSV list into one multi-page PDF, or a unique certificate ID. It can also help you subset a large font so the generated PDFs stay small.

Prompt to recreate it

Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:

text
Build a certificate generator with jsPDF and a PDF.js 3 live preview (both from a CDN) in plain HTML, CSS and JavaScript.

Requirements:
- Form fields: recipient name, course, date, hours, signer and a three-option colour theme.
- Fetch a Google Fonts script TTF (Great Vibes) at startup, convert it to base64 in chunks, embed it with addFileToVFS and addFont, and fall back to Times Italic if loading fails.
- Draw a landscape A4 certificate in millimetres: a thick outer border and thin inner border with corner dots, a spaced-out heading, the recipient name in the script font reduced in size until it fits, an underline, the wrapped course title, hours, a date line on the left, a signature line on the right with the signer's name in script, and a round seal in the centre.
- Regenerate on every edit (debounced) and render the PDF with PDF.js onto a canvas, passing it a copy of the bytes and ignoring outdated renders.
- A Download button that saves the PDF with the recipient's name in the file name and a note that sandboxed previews block downloads.

Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.

Source Code

<div class="jcg">
  <form class="jcg-form" id="jcgForm" autocomplete="off">
    <h2>Certificate of completion</h2>
    <label>Recipient name <input name="name" value="Amara Okafor" maxlength="40"></label>
    <label>Course <input name="course" value="Advanced Accessible Interfaces" maxlength="60"></label>
    <div class="jcg-row">
      <label>Date <input name="date" type="date" value="2026-09-25"></label>
      <label>Hours <input name="hours" type="number" min="1" max="500" value="24"></label>
    </div>
    <label>Signed by <input name="signer" value="Dr. Lena Park, Programme Lead" maxlength="50"></label>
    <fieldset class="jcg-theme">
      <legend>Theme</legend>
      <label><input type="radio" name="theme" value="navy" checked> Navy &amp; gold</label>
      <label><input type="radio" name="theme" value="forest"> Forest</label>
      <label><input type="radio" name="theme" value="plum"> Plum</label>
    </fieldset>
    <button type="button" id="jcgDownload">Download PDF</button>
    <p class="jcg-status" id="jcgStatus" role="status">Loading script font…</p>
  </form>
  <div class="jcg-preview"><canvas id="jcgCanvas" aria-label="Rendered certificate PDF"></canvas></div>
</div>

Step by step

How to Use

  1. 1
    Load jsPDF and PDF.jsBoth from the CDN; the script font is fetched at startup.
  2. 2
    Fill in the detailsName, course, date, hours and signer; the preview follows.
  3. 3
    Try a long nameThe font size shrinks to keep it inside the border.
  4. 4
    Pick a themeNavy and gold, forest or plum.
  5. 5
    DownloadSaves a print-ready landscape A4 PDF.

Real-world uses

Common Use Cases

Online courses
Completion certificates per learner.
Workshops and events
Attendance certificates on the spot.
HR and training
Compliance training records.
Schools and clubs
Awards and achievements.
Gift vouchers
The same layout techniques for vouchers.
Related: jsPDF Invoice Generator
Tables and totals with autoTable: jsPDF Invoice Generator with Live PDF Preview.
Related: Certificate Preview Card
An HTML certificate card: Certificate of Completion Preview.

Got questions?

Frequently Asked Questions

Load a TrueType (.ttf) file, convert it to base64, call doc.addFileToVFS('Font.ttf', base64) and doc.addFont('Font.ttf', 'FontName', 'normal'), then doc.setFont('FontName', 'normal').

No. jsPDF needs TrueType fonts. Download the .ttf version, which Google Fonts provides in its GitHub repository and download archives.

Measure it with doc.getTextWidth(text) at the current font size and reduce the size until it is narrower than the space available, with a sensible minimum.

Pass the horizontal centre as the x coordinate and { align: 'center' } as options: doc.text(text, pageWidth / 2, y, { align: 'center' }).

String.fromCharCode.apply on a very large array can exceed the engine's maximum number of function arguments. Processing the bytes in chunks keeps each call within the limit.