In short
Course certificates for a printing workshop, one page per student, with a patterned border and a seal. Writing a student's name once gives a whole certificate.
What you'll build
End-of-course certificates for the Quoin Room, a fictional letterpress workshop in Providence: one US Letter page per student. The Spanish edition sets them as A4 diplomas for La Cuña, a workshop in Zaragoza. A teal band filled with cream guilloche lenses frames the sheet, with a cream rosette at each corner; both are drawn in code from sine curves and hypotrochoids. Under a title in tracked capitals, the student's name is set in 48 pt Pinyon Script above a gold rule, and the citation is centred in Rosarivo. A red seal with two ribbon tails sits between the signature lines, with a one-line imprint below. Because one heading style draws the whole page, each student is one Markdown heading, and the PDF holds the class with a bookmark per name.
This recipe answers
- How do I add a watermark, a background tint or a decorative image on every page?
- How do I set unnumbered artwork: ornaments, vignettes, logos?
- How do I pin a badge or sticker to a fixed position on the page?
- How do I export a real PDF in the browser with the fonts embedded?
The short answer
const certificate = () => ({ // a function: it uses the elements defined below
id: 'certificate',
// Section geometry, for this style's pages only: a narrower measure, and a text area that
// ends at the seal, so a citation too long for the page moves on instead of running under it.
margins: { left: mm(SIDE), right: mm(SIDE), bottom: mm(H - SIGN) },
// Header and footer elements paint over the page and reserve nothing (gotcha:
// header-paints-over-text), so the frame, the seal and the signatures go there. In the
// opener the signature lines would count towards its height (gotcha:
// opener-reserves-anchored), and a design that reaches below the text area takes the page.
header: { elements: [frame, serial] },
footer: { elements: signatures },
// The citation starts 18 lines of the 17 pt grid under the top margin, 140 mm down (19
// lines, 146 mm, on A4): an opener's height rounds up to whole lines, and without
// marginBottom: 0 the level's 0.5 em under a heading would add a line. minHeight is a
// floor: the title block alone would start the citation at 128 mm (134 mm on A4).
advancedDesign: { enabled: true, minHeight: mm(y(106)), slot: { elements: title } },
marginBottom: mm(0),
});
// Hook-up: headingStyles: [certificate()], and in the Markdown one heading per student:
// # Imogen Achterberg {style="certificate" serial="26-031"}
One heading style draws the whole certificate
Ingredients
- Features
- Running heads per sectionPictures in page designsDesigned openersAnchoring design elementsText, rules and boxes in page designsHeading stylesSection geometryHeading attributesPaper colourSemantic colour paletteFigures and tables as resourcesDocument metadataPages on a canvasPDF exportFonts embedded in the PDFPDF bookmarks
- Type
- Rosarivo, Pinyon Script, Aboreto (SIL OFL 1.1)
- Assets
- None: every picture is drawn in code
Method
#1 · Let one heading style draw the page
The style itself is the short answer above. A heading style governs the pages of its section (heading styles): its header and footer replace the document's, which are empty here, its margins set the text area and its advancedDesign draws the opener. An opener's height rounds up to whole lines of the 17 pt body grid. A minHeight of 106 mm becomes 18 lines, so the citation starts 140 mm from the top edge; on A4, y() makes it 112.7 mm, or 19 lines, and the citation starts at 146 mm. The title block alone would start the citation at 128 mm (134 mm on A4). Without marginBottom: 0, the default 0.5 em under a heading would push the same 106 mm to 19 lines.
#2 · Hang the frame from the page in the header
const frame = { kind: 'image', id: 'frame', resourceId: 'guilloche',
placement: { anchor: { to: 'page', edge: 'top-left' }, // the trim box
size: { width: 'fill', height: 'fill' } } }; // the SVG has the page's proportions
const serial = { kind: 'text', id: 'serial', ...caps, fontSize: pt(8.5), letterSpacing: pt(1.6),
content: t({ en: 'No. {attr.serial}', es: 'N.º {attr.serial}' }), // from the heading line
color: col('seal'), align: 'right', placement: at('top-right', -MARGIN, 29) };
const PX = 10; // declared pixels per mm: an SVG resource only needs the right proportions
const svg = (id, w, h, altText) => ({ id, typeId: 'figure', kind: 'svg', createdAt: 0,
updatedAt: 0, altText, svg: { fileId: `${id}.svg`, width: w * PX, height: h * PX } });
const resources = [
svg('guilloche', W, H, t({ en: 'A teal guilloche border with cream rosettes at the corners.',
es: 'Una orla de guilloché verde azulado con rosetas color crema en las esquinas.' })),
svg('seal', SEAL.w, SEAL.h, t({ en: 'A red seal with a serrated edge and two ribbon tails.',
es: 'Un sello rojo de borde dentado con dos cintas.' })),
];
An image element draws a resource at the size of its placement (image elements): anchored to the page's top-left corner with both sides 'fill', the guilloche covers the trim box, and the SVG, declared with the page's proportions, fills it without stretching. The header paints it over page.backgroundColor and reserves no room, so the margins alone keep the text at least 32 mm from the trim, inside the inner rule at 26 mm. A watermark placed in the header would print over the words, because the header is painted after the text. In a header, {attr.serial} reads the attribute of the heading whose section the page belongs to, so each certificate prints its own number.
#3 · Keep only the title block in the opener
const centred = (top) => at('top', 0, y(top)); // tracked or not, the letters are centred
const title = [
{ kind: 'text', id: 'kicker', ...caps, fontSize: pt(9.5), letterSpacing: pt(2.4),
content: '{attr.workshop}', placement: centred(39) }, // the wording: see merge
{ kind: 'text', id: 'title', content: t({ en: 'Certificate', es: 'Diploma' }), ...caps,
fontSize: pt(46), lineHeight: 1, letterSpacing: pt(3), placement: centred(48) },
{ kind: 'text', id: 'of', content: t({ en: 'of completion', es: 'de aprovechamiento' }),
...caps, fontSize: pt(11), letterSpacing: pt(4), placement: centred(68) },
{ kind: 'text', id: 'lead', content: '{attr.lead}',
fontFamily: 'Rosarivo', italic: true, fontSize: pt(13), color: col('muted'),
placement: centred(90) },
{ kind: 'text', id: 'name', content: '{titleText}', fontFamily: 'Pinyon Script',
fontSize: pt(48), lineHeight: 1.25, // 60 pt from line to line of a long name
color: col('ink'), align: 'center', overflow: 'wrap', // a long name takes a second line
placement: { ...centred(97), size: { width: mm(W - 2 * MARGIN) } } },
{ kind: 'rule', id: 'underline', direction: 'horizontal', thickness: pt(0.75),
color: col('gold'), placement: { anchor: { to: '#name', edge: 'below' },
offset: { x: mm(18), y: mm(5) }, size: { width: mm(W - 2 * MARGIN - 36) } } },
];
Each line is anchored to the page's 'top' edge, which centres it, with a y measured from the trim, so the block keeps its place whatever the margins; y() stretches those positions from Letter to A4. The name is the heading's own text, read through {titleText}, so the PDF bookmarks and tags carry it. A long name takes a second line, since a heading design wraps its text (overflow: 'wrap'). The tracked lines need no correction: the tracking after the last letter is left out of the measure, so the letters themselves are centred.
#4 · Hang the seal and the signatures from one edge
// mm: each signature line stops 3 mm short of the seal (56 on Letter, 53 on A4)
const LINE = (W - 2 * MARGIN - 2 * SEAL.r) / 2 - 3;
const under = (id, gap, x = 0) => ({ anchor: { to: `#${id}`, edge: 'below' },
offset: { x: mm(x), y: mm(gap) }, size: { width: mm(LINE) } });
const signatures = [
{ kind: 'image', id: 'seal', resourceId: 'seal',
placement: { ...at('top', 0, SIGN), size: { width: mm(SEAL.w) } } },
...[1, 2].flatMap((n, i) => [ // signer1 and role1, signer2 and role2: the wording again
{ kind: 'rule', id: `line${i}`, direction: 'horizontal', thickness: pt(0.6), color: col('rule'),
placement: { ...at('top-left', i ? W - MARGIN - LINE : MARGIN, SIGN + 23),
size: { width: mm(LINE) } } },
{ kind: 'text', id: `who${i}`, content: `{attr.signer${n}}`, fontFamily: 'Rosarivo',
fontSize: pt(10.5), color: col('ink'), align: 'center', placement: under(`line${i}`, 1.6) },
{ kind: 'text', id: `role${i}`, content: `{attr.role${n}}`, ...caps, fontSize: pt(7.5),
letterSpacing: pt(1.4), color: col('muted'), align: 'center',
placement: under(`who${i}`, 0.6) },
]),
{ kind: 'text', id: 'imprint', fontFamily: 'Rosarivo', italic: true, fontSize: pt(7),
content: '{attr.imprint}', color: col('muted'), placement: at('top', 0, SIGN + 50) },
];
Everything in the footer is measured from SIGN, the seal's top edge, and the style's bottom margin ends the text area at the same edge, so a citation too long for the page moves on to the next one instead of running under the seal. Moved into the opener, the lines and the names would count towards its height (span and advanced design); since they reach below the text area, the opener would claim the whole page and send the citation to the next one. LINE takes the width between the page margins, subtracts the seal's 34 mm disc, halves the rest and takes off 3 mm, so each line stops 3 mm short of the seal on both trims (56 mm long on Letter, 53 mm on A4). Each name and role is a text element as wide as its line, which centres it under the line.
#5 · Merge the class list into headings
// Name and serial: {titleText} and {attr.serial} in the designs (gotcha: attr-values). The
// lines every certificate shares are the front matter of content.<lang>.md, written onto each
// heading as attributes too: {attr.workshop}, {attr.lead}, the signers and the imprint.
const { metadata: wording, content: citation } = extractFrontmatter(markdown);
const shared = Object.entries(wording).map(([key, value]) => `${key}="${value}"`).join(' ');
const heading = (name, serial) => `# ${name} {style="certificate" serial="${serial}" ${shared}}`;
const CLASS = t({
en: [['Imogen Achterberg', '26-031'], ['Tomás Okafor', '26-032'], ['Ruth Adair', '26-033']],
es: [['Lucía Beltrán Ochoa', '26-017'], ['Íñigo Sarasola', '26-018'], ['Ana Rius', '26-019']],
});
const merged = CLASS.map(([name, serial]) => `${heading(name, serial)}\n\n${citation}`)
.join('\n\n');
const metadata = { // the PDF's title and author
title: t({ en: 'Certificates of completion, fall 2026',
es: 'Diplomas del curso de otoño de 2026' }),
author: t({ en: 'The Quoin Room', es: 'La Cuña' }) };
Each row becomes a # heading that names the style and carries the serial as an attribute (heading attributes), followed by the wording from content.en.md, so three rows give three pages. Level 1's breakBefore with parity 'any' starts each heading on a new page with no blank page between certificates; the style inherits it.
#6 · Build one PDF for the whole class
offerPdf(() => renderToPdf(doc, { fontProvider: fontsourceProvider, resourceBytes: imageBytes }),
`${RECIPE}.pdf`); // bookmarks: one per heading, so one per student
document.querySelector('[data-postext-pdf]').textContent = t({ en: 'Class list → one PDF',
es: 'Toda la clase en un PDF' });
The class is one document, so renderToPdf writes a single three-page file with a bookmark per heading, each named after a student. renderToPdf also takes an array of documents, such as the chapters of a book, but a document per student means one buildDocument call for each. As headings, the whole class is laid out in one build, and the viewer shows all three certificates from that build. The PDF embeds the four faces the pages print, which the kit's font provider fetches from Fontsource (why a font provider?).
The whole recipe
// ═══ Postext Cookbook · Nº 063 · Certificate with a guilloche border ═══════════════
// https://postext.dev/en/cookbook/certificate-single-page
// Code: MIT · Text: original (CC BY 4.0) · Guilloche and seal: generated in code (CC BY 4.0)
// Fonts: Rosarivo, Pinyon Script, Aboreto (SIL OFL 1.1) · Needs postext ≥ 1.34.0
// End-of-course certificates, one page per student, drawn by one heading style, in one PDF.
import {
buildDocumentWithFonts, renderPageToCanvas, registerResourceImage, extractFrontmatter,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'certificate-single-page';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = {
ink: '#1f2a2e', // text and the student's name
teal: '#1f5f5b', // the frame, the title lines
gold: '#b08d57', // hairlines and the rule under the name; never text (2.9:1 on paper)
seal: '#8d2c2c', // the seal and the serial number
rule: '#8f8878', // signature lines
muted: '#6d6a60', // the lead-in, the signatories' roles, the imprint
paper: '#fbf8ef', // the sheet
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries(palette)
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
const [W, H] = t({ en: [215.9, 279.4], es: [210, 297] }); // US Letter; A4 for the Spanish diploma
const MARGIN = 32; // mm on every side, inside the frame's inner rule (26 mm in)
const SIDE = 50; // mm: the certificate's side margins, a 116 mm measure (110 on A4)
// Positions are drawn on US Letter and stretched to A4: y(90) is 90 mm down on Letter.
const y = (mm) => (mm * H) / 279.4;
const SIGN = y(194); // mm from the top: the seal's top edge, where the text area ends
const SEAL = { w: 40, h: 45, r: 17 }; // mm: the seal with its ribbon tails, and its disc's radius
const at = (edge, x, top) => ({ anchor: { to: 'page', edge }, offset: { x: mm(x), y: mm(top) } });
const caps = { fontFamily: 'Aboreto', textTransform: 'uppercase', color: col('teal') };
// #region answer: one heading style draws the whole certificate
const certificate = () => ({ // a function: it uses the elements defined below
id: 'certificate',
// Section geometry, for this style's pages only: a narrower measure, and a text area that
// ends at the seal, so a citation too long for the page moves on instead of running under it.
margins: { left: mm(SIDE), right: mm(SIDE), bottom: mm(H - SIGN) },
// Header and footer elements paint over the page and reserve nothing (gotcha:
// header-paints-over-text), so the frame, the seal and the signatures go there. In the
// opener the signature lines would count towards its height (gotcha:
// opener-reserves-anchored), and a design that reaches below the text area takes the page.
header: { elements: [frame, serial] },
footer: { elements: signatures },
The composed script.js runs as it is: paste it into any page’s module script, or open the recipe on CodePen. Recipe folder on GitHub ↗ (opens in a new tab)
Variations
#Print a PDF per student
One button per student builds that certificate as a document of its own, with buildDocumentWithFonts as the pen's own build, and names the file after the serial number; each file weighs about 245 KB.
-offerPdf(() => renderToPdf(doc, { fontProvider: fontsourceProvider, resourceBytes: imageBytes }),
- `${RECIPE}.pdf`); // bookmarks: one per heading, so one per student
-document.querySelector('[data-postext-pdf]').textContent = t({ en: 'Class list → one PDF',
- es: 'Toda la clase en un PDF' });
+for (const [name, serial] of CLASS) {
+ const one = `${heading(name, serial)}\n\n${citation}`;
+ offerPdf(async () => renderToPdf(await buildDocumentWithFonts({ markdown: one, metadata,
+ resources }, config(), kitFonts(FONTS)), { fontProvider: fontsourceProvider,
+ resourceBytes: imageBytes }), `${serial}.pdf`);
+ document.querySelector(`[data-postext-pdf="${serial}.pdf"]`).textContent = name;
+}#Print the frame and the title in navy
The SVG art and the config read the same palette object, so changing one entry recolours the band, the rosette patterns and the title lines.
- teal: '#1f5f5b', // the frame, the title lines
+ teal: '#2b3a67', // the frame, the title linesPitfalls
Pitfall
An opener reserves height down to its lowest page-anchored element
An advanced-design opener reserves the height of its lowest element, and page- or bleed-anchored elements below the heading count too, so decoration at the foot of the page pushes the text to the next page. Give such an element reserve: false (since postext 1.5): it is painted where it is anchored and reserves nothing. Elements that follow the band itself (anchored to its foot, or 'fill' tall) never set its height. Designed openers →
Pitfall
Header and footer elements paint over text
Header and footer elements are painted over the page and the text area does not make room for them. Keep them within the margins, which are what reserve their space. Running heads and folios →
Pitfall
Attribute values: no { or }; single-quote a value with "
An attribute value ends at the closing brace, so it cannot hold { or }. A value that contains a double quote goes in single quotes; a dollar sign is fine. Heading attributes →
Pitfall
No <marker> or filters in SVG art (raster fallback)
An SVG figure stays vector in the PDF only without <marker>, filters and masks; otherwise it falls back to a raster, and deeply nested filters can blank it in Chrome. Draw arrowheads as paths. Figures and tables as resources →
Credits
- Recipe
- Ignacio Ferro
- Text
- Original prose, CC BY 4.0
- Fonts
- Rosarivo (SIL OFL 1.1) · Pinyon Script (SIL OFL 1.1) · Aboreto (SIL OFL 1.1)
Edit this write-up ↗ (opens in a new tab)Recipe folder on GitHub ↗ (opens in a new tab)


