Skip to content

Certificate of Completion

An ornate landscape certificate with decorative nested borders, centred typography, and a colour scheme drawn from navy and gold.

Every text element is horizontally centred by measuring its rendered width with font.widthOfTextAtSize() and computing x = (W - textWidth) / 2. The border decoration is built from two drawRectangle calls (outer navy, inner gold) with no fill, layered over a warm ivory background.

  • Landscape page — page dimensions are swapped to [842, 595].
  • Centred text — width measured before drawing; no manual guess needed.
  • Mixed typography — three weights/styles from the Helvetica family (HelveticaBold, Helvetica, HelveticaOblique) at varying sizes.
  • Layered decoration — accent bars at top and bottom bracket the content and share the same palette as the border.
Parameter Effect
Recipient Large italic name on the certificate
Course Bold course / achievement title
Issuer Organisation name in the top accent bar
Date Completion date shown below the course title
"use strict";
const { PDFDocument, StandardFonts, rgb } = require('pdf-lib');
const W = 842, H = 595;
function getParameterDefinitions() {
return [
{ name: 'recipient', type: 'text', default: 'Jane Smith', caption: 'Recipient name' },
{ name: 'course', type: 'text', default: 'Advanced TypeScript', caption: 'Course / achievement' },
{ name: 'issuer', type: 'text', default: 'Acme Learning Institute',caption: 'Issuing organisation' },
{ name: 'date', type: 'text', default: '1 January 2026', caption: 'Completion date' },
];
}
async function main({ recipient, course, issuer, date }) {
const doc = await PDFDocument.create();
const bold = await doc.embedFont(StandardFonts.HelveticaBold);
const reg = await doc.embedFont(StandardFonts.Helvetica);
const italic = await doc.embedFont(StandardFonts.HelveticaOblique);
const page = doc.addPage([W, H]);
const navy = rgb(0.10, 0.20, 0.45);
const gold = rgb(0.72, 0.57, 0.18);
const ivory = rgb(0.98, 0.97, 0.93);
const dark = rgb(0.12, 0.12, 0.12);
const white = rgb(1, 1, 1);
// ── Background ────────────────────────────────────────────────────────────
page.drawRectangle({ x: 0, y: 0, width: W, height: H, color: ivory });
// ── Nested border ─────────────────────────────────────────────────────────
const bm = 18;
page.drawRectangle({ x: bm, y: bm, width: W - bm*2, height: H - bm*2, borderColor: navy, borderWidth: 3 });
page.drawRectangle({ x: bm + 9, y: bm + 9, width: W - (bm+9)*2, height: H - (bm+9)*2, borderColor: gold, borderWidth: 1.5 });
// ── Top accent bar ────────────────────────────────────────────────────────
page.drawRectangle({ x: bm + 3, y: H - bm - 52, width: W - (bm+3)*2, height: 49, color: navy });
const issuerW = bold.widthOfTextAtSize(issuer, 13);
page.drawText(issuer, { x: (W - issuerW) / 2, y: H - bm - 33, size: 13, font: bold, color: white });
// ── "Certificate of Completion" ───────────────────────────────────────────
const heading = 'Certificate of Completion';
const headingW = bold.widthOfTextAtSize(heading, 30);
page.drawText(heading, { x: (W - headingW) / 2, y: H - 160, size: 30, font: bold, color: navy });
// Gold rule under heading
page.drawLine({ start: { x: W/2 - 110, y: H - 175 }, end: { x: W/2 + 110, y: H - 175 }, thickness: 1.2, color: gold });
// ── Body copy ─────────────────────────────────────────────────────────────
function centred(text, y, size, font, color) {
page.drawText(text, { x: (W - font.widthOfTextAtSize(text, size)) / 2, y, size, font, color });
}
centred('This is to certify that', H - 215, 12, reg, dark);
centred(recipient, H - 268, 34, italic, navy);
// Underline recipient name
const rw = italic.widthOfTextAtSize(recipient, 34);
page.drawLine({
start: { x: (W - rw) / 2, y: H - 275 },
end: { x: (W - rw) / 2 + rw, y: H - 275 },
thickness: 0.8, color: gold,
});
centred('has successfully completed', H - 308, 12, reg, dark);
centred(course, H - 346, 19, bold, navy);
centred(`Awarded on ${date}`, H - 394, 10, reg, rgb(0.45, 0.45, 0.45));
// ── Bottom accent bar ─────────────────────────────────────────────────────
page.drawRectangle({ x: bm + 3, y: bm + 3, width: W - (bm+3)*2, height: 34, color: navy });
const motto = 'Excellence · Achievement · Growth';
page.drawText(motto, { x: (W - reg.widthOfTextAtSize(motto, 10)) / 2, y: bm + 13, size: 10, font: reg, color: gold });
return doc;
}
module.exports = { main, getParameterDefinitions };