In short
A two-page price offer from a German window workshop. It shows how to place the address and other parts of a business letter where the German standard puts them, so it fits a window envelope.
What you'll build
Fensterwerkstatt Tessin, an invented Berlin workshop that restores box windows, sends a quotation to the managing agents of a block of flats. It runs to two A4 sheets in German, laid out to form B of DIN 5008. A Berlin-blue band across the top carries the workshop’s logo and name. Under it, each part sits where the standard puts it: the return line and the address inside the 85 × 45 mm field that shows through the window of a DL envelope, the information block 125 mm from the left edge, the bold subject two blank lines under the field, and fold and punch marks at 105, 148.5 and 210 mm. The company data run in three columns at the foot of both sheets. The second sheet repeats the reference next to “Seite 2 von 2” and ends on a signature drawn in code.
This recipe answers
- How do I pin a badge or sticker to a fixed position on the page?
- How do I add a watermark, a background tint or a decorative image on every page?
- How do I hide running heads on openers and blank pages, or paint a blank verso in the part colour?
- How do I set an epigraph, a dedication, a signature, or a pull quote with a big quote mark?
The short answer
const at = (x, y, size) => ({ anchor: { to: 'page', edge: 'top-left' }, // mm from the corner
offset: { x: mm(x), y: mm(y) }, ...(size && { size }) });
const ZONE = DIN.field.y + DIN.notes; // 62.7 mm: where the six address lines start
const SUBJECT = DIN.field.y + DIN.field.h + 2 * LEAD * PT; // two blank lines under the field
const firstPage = () => ({ enabled: true, slot: { elements: [ // in paint order
...letterhead(), // band, logo and name, and the corners of the window
text('from', FROM, FACE.from, at(DIN.left, ZONE - 3.6)), // the return line, underlined
rule('from-rule', 'muted', { anchor: { to: '#from', edge: 'below' }, offset: { y: mm(0.6) },
size: { width: mm(WINDOW) } }),
// One attribute holds the whole address: each '\n' in it starts a new line.
text('to', '{attr.to}', FACE.address, at(DIN.left, ZONE, { width: mm(WINDOW) })),
...infoBlock(), // labels, and values from {attr.*}
text('subject', '{titleText}', FACE.subject, at(DIN.left, SUBJECT, { width: mm(TEXT) })),
] } });
// The H1 reserves the sheet down to its lowest element (gotcha: opener-reserves-anchored).
// fontFamily: the design paints the H1, but the build measures it (default: Open Sans).
const headings = () => ({ fontFamily: 'Familjen Grotesk', levels: [{ level: 1,
breakBefore: { enabled: true, parity: 'any' }, // a letter starts on the next sheet
marginBottom: pt(2 * LEAD), // two blank lines between the subject and the salutation
advancedDesign: firstPage() }] });
The subject line's design pins page 1 to the sheet at form B's positions
Ingredients
- Features
- Anchoring design elementsDesigned openersHeading attributesText, rules and boxes in page designsPictures in page designsFull-width chapter bandHeads by page roleRunning heads and foliosFigures exactly hereFigures and tables as resourcesCustom resource typesParagraph stylesHyphenation and document languageTrim sizeSemantic colour palettePDF exportFonts embedded in the PDFPages on a canvas
- Type
- Nunito Sans, Familjen Grotesk, Reddit Mono (SIL OFL 1.1)
- Assets
- None: every picture is drawn in code
Method
#1 · Pin the first page to the sheet in millimetres
const at = (x, y, size) => ({ anchor: { to: 'page', edge: 'top-left' }, // mm from the corner
offset: { x: mm(x), y: mm(y) }, ...(size && { size }) });
const ZONE = DIN.field.y + DIN.notes; // 62.7 mm: where the six address lines start
const SUBJECT = DIN.field.y + DIN.field.h + 2 * LEAD * PT; // two blank lines under the field
const firstPage = () => ({ enabled: true, slot: { elements: [ // in paint order
...letterhead(), // band, logo and name, and the corners of the window
text('from', FROM, FACE.from, at(DIN.left, ZONE - 3.6)), // the return line, underlined
rule('from-rule', 'muted', { anchor: { to: '#from', edge: 'below' }, offset: { y: mm(0.6) },
size: { width: mm(WINDOW) } }),
// One attribute holds the whole address: each '\n' in it starts a new line.
text('to', '{attr.to}', FACE.address, at(DIN.left, ZONE, { width: mm(WINDOW) })),
...infoBlock(), // labels, and values from {attr.*}
text('subject', '{titleText}', FACE.subject, at(DIN.left, SUBJECT, { width: mm(TEXT) })),
] } });
// The H1 reserves the sheet down to its lowest element (gotcha: opener-reserves-anchored).
// fontFamily: the design paints the H1, but the build measures it (default: Open Sans).
const headings = () => ({ fontFamily: 'Familjen Grotesk', levels: [{ level: 1,
breakBefore: { enabled: true, parity: 'any' }, // a letter starts on the next sheet
marginBottom: pt(2 * LEAD), // two blank lines between the subject and the salutation
advancedDesign: firstPage() }] });
at() anchors an element by its top-left corner to 'page', the trim box (element placement), so each x and y is a distance from the corner of the sheet and the figures of the standard go in unchanged: the address at 25 mm across and 62.7 mm down, the first label of the information block at 125 and 50. These elements form the design of the H1. The heading’s text is the subject ({titleText}) and its attributes hold the address and the references, so the config holds the stationery and the Markdown holds the letter. The subject, at 100.6 mm, is the lowest element, so the heading reserves the sheet down to the subject’s foot. marginBottom adds the two blank lines, and the salutation starts on the next grid line, at 117 mm.
The address is one attribute with \n between its lines, and each \n starts a new line in the design text. The heading sits in the text column, and its design still paints the band, the logo and the name above the 27 mm top margin, since each element is pinned to the page.
#2 · Chain the information block from one pinned label
const INFO = [['Ihr Zeichen', 'ihr-zeichen'], ['Ihre Nachricht vom', 'ihre-nachricht'],
['Unser Zeichen', 'unser-zeichen'], ['Name', 'name'], ['Telefon', 'telefon'],
['E-Mail', 'email'], ['Datum', 'datum']]; // [label, heading attribute]
const VALUE = 29; // mm from the labels to the values
const infoBlock = () => INFO.flatMap(([label, key], i) => [
text(`label-${i}`, label, FACE.label, i === 0 ? at(DIN.info.x, DIN.info.y) : {
anchor: { to: `#label-${i - 1}`, edge: 'below' }, // each label under the last
offset: { y: mm(key === 'datum' ? ROW * PT : 0) } }), // a blank row before the date
text(`value-${i}`, `{attr.${key}}`, FACE.value, { // a 12 pt row as well, on the label's baseline
anchor: { to: `#label-${i}`, edge: 'align-top' }, offset: { x: mm(VALUE) },
size: { width: mm(DIN.info.w - VALUE) } }),
]);
Only the first label is pinned to the sheet. Every other label is anchored 'below' the one before it, and each value to its label with 'align-top' and a 29 mm offset, so a row added to INFO needs no coordinates. Design text sets its baseline at 80% of the line box. The 7 pt label and the 9 pt value both set lineHeight: pt(ROW), a 12 pt line, so they share a baseline on every 4.23 mm row.
#3 · Draw the letterhead into the same design
const [BAND, TICK] = [32, 3]; // mm: the band's depth, each arm of the window's corner angles
const LOGO = { y: 7, h: 18 }; // mm: the mark, centred in the band
const CRAFTS = 3 * 7.5 * 1.45 * PT; // mm: three 7.5 pt lines at 1.45
const letterhead = () => [
{ kind: 'box', id: 'band', style: { backgroundColor: col('brand') },
placement: at(0, 0, { width: 'fill', height: mm(BAND) }) },
{ kind: 'image', id: 'logo', resourceId: 'logo',
placement: at(DIN.left, LOGO.y, { height: mm(LOGO.h) }) },
text('name', 'Tessin', face('Familjen Grotesk', 30, 700, 'paper', { lineHeight: 1 }),
{ anchor: { to: '#logo', edge: 'right-of' }, offset: { x: mm(5), y: mm(1.2) } }),
text('trade', 'FENSTERWERKSTATT · BERLIN', face('Reddit Mono', 7.5, 500, 'sky',
{ letterSpacing: pt(1.2) }), { anchor: { to: '#name', edge: 'below' },
offset: { x: mm(0.4), y: mm(1.5) } }),
text('crafts', 'Kastenfenster\nHolzfenster\nDenkmalpflege', face('Reddit Mono', 7.5,
400, 'sky', { lineHeight: 1.45, align: 'right' }),
at(210 - DIN.right - 45, LOGO.y + (LOGO.h - CRAFTS) / 2, { width: mm(45) })),
...[[0, 0], [1, 0], [0, 1], [1, 1]].flatMap(([right, low], i) => { // turned inwards
const [x, y] = [DIN.field.x + right * DIN.field.w, DIN.field.y + low * DIN.field.h];
return [rule(`across-${i}`, 'marks', at(x - right * TICK, y, { width: mm(TICK) })),
rule(`down-${i}`, 'marks', at(x, y - low * TICK, { height: mm(TICK) }), 'vertical')];
}),
];
The band is a box pinned to the corner of the sheet. width: 'fill' stretches it from edge to edge, and its 32 mm depth takes it 5 mm past the 27 mm top margin. The logo is an image element that draws a resource 18 mm tall and takes its width from the drawing (image elements). The name hangs 'right-of' the logo, and the trade line 'below' the name. Eight 3 mm rules draw an angle at each corner of the 85 × 45 mm address field, the part of the sheet the envelope window shows.
#4 · Put what every sheet shares in the header and footer
const header = { elements: [
// In the H1's design they would stretch its reserve (gotcha: opener-reserves-anchored).
...[[DIN.folds[0], 5], [DIN.punch, 8], [DIN.folds[1], 5]].map(([y, length], i) =>
rule(`mark-${i}`, 'marks', at(0, y, { width: mm(length) }))), // fold, punch, fold
// Page 1 opens with the H1, which makes it an 'opener'; later sheets are 'body' pages.
{ kind: 'box', id: 'strip', pages: 'body', style: { backgroundColor: col('brand') },
placement: at(0, 0, { width: 'fill', height: mm(4) }) },
text('ref', 'Fensterwerkstatt Tessin · Unser Zeichen {attr.unser-zeichen} · {attr.datum}',
FACE.small, at(DIN.left, 13.2), { pages: 'body' }),
text('page', 'Seite {pageNumber} von {totalPages}', FACE.small,
at(210 - DIN.right - 40, 13.2, { width: mm(40) }), { pages: 'body', align: 'right' }),
] };
const FOOT = 297 - DIN.bottom + 5; // mm: the hairline over the company data
const COMPANY = [ // three columns, 57 mm apart, inside the bottom margin
'Fensterwerkstatt Tessin GmbH\nRennbahnstraße 48\n13086 Berlin\nTelefon 030 23125-400',
'Geschäftsführer Martin Tessin\nAmtsgericht Charlottenburg\nHRB 000000 B\nUSt-IdNr. DE000000000',
'Musterbank Berlin\nIBAN DE00 0000 0000 0000 0000 00\nBIC MUSTDEBBXXX',
];
const footer = { elements: [
rule('foot-rule', 'rule', at(DIN.left, FOOT, { width: mm(TEXT) })),
...COMPANY.map((lines, i) => text(`company-${i}`, lines, FACE.small,
at(DIN.left + 57 * i, FOOT + 2.5, { width: mm(52) }))),
] };
An element of the H1’s design pinned below the subject adds to the height the heading reserves. With the 210 mm fold mark in the design, the salutation drops to 222.8 mm and the letter runs to three pages. The header slot paints on every page and reserves no space, so the three marks go there (headers and footers). Page 1 opens with the H1, which makes it an 'opener' page, so pages: 'body' limits the blue strip, the reference line and Seite {pageNumber} von {totalPages} to the sheets that follow. The reference line reads the H1’s attributes through {attr.unser-zeichen} and {attr.datum}.
#5 · Set the signature in the flow
const resourceTypes = [{ id: 'drawing', name: 'Zeichnung', shortLabel: 'Zeichnung',
numberingTemplate: '{n}', resetOn: 'never', counterFormat: 'decimal', captionPrefix: '' }];
const drawing = (id, width, height, altText, placement) => ({ id, typeId: 'drawing',
kind: 'svg', svg: { fileId: `${id}.svg`, width, height }, altText, placement,
createdAt: 0, updatedAt: 0 });
const resources = [ // an image element draws the logo; nothing cites it
drawing('logo', 200, 280, 'Zeichen der Fensterwerkstatt Tessin, ein Kastenfenster'),
drawing('signature', 760, 328, 'Unterschrift von Martin Tessin',
{ position: 'here', width: 0.297 }), // 49 × 21.1 mm: under 4 lines, no grid gap below
];
::resource{id="signature"} sets the drawing under “Mit freundlichen Grüßen”, and width: 0.297 makes it 49 mm wide and 21.1 mm deep, just under four 15 pt lines. The text after a resource in the flow returns to the body’s grid. At 0.25 the drawing was 17.8 mm deep, and the 3.4 mm the grid added under it pushed the name away from the signature. The resource type has an empty captionPrefix, and Postext sets no caption when both the prefix and the caption are empty, so no label or number appears under the signature (resource types). The logo is a resource of the same type, drawn only by the image element. No :ref or ::resource names it, so it never enters the flow.
The whole recipe
// ═══ Postext Cookbook · Nº 058 · Business letter to DIN 5008 ═════════════════════
// https://postext.dev/en/cookbook/din-business-letter
// Code: MIT · Text: original, in German (CC BY 4.0) · Logo, signature: drawn in code (CC BY 4.0)
// Fonts: Nunito Sans, Familjen Grotesk, Reddit Mono (SIL OFL 1.1) · Needs postext ≥ 1.34.0
// A German quotation on A4 whose H1 design pins the letterhead and the address to DIN 5008.
import {
buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} 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 = 'din-business-letter';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = {
ink: '#1f2429', brand: '#1b4a73', // text, a blue-grey near-black; Berlin blue, for the band
sky: '#b4cbe0', paper: '#ffffff', // the trade and the crafts on the band; the logo and name
muted: '#5b6670', pen: '#26408f', // labels, return line, company data; the signature's ink
marks: '#98a3ad', rule: '#c9d1d8', // fold marks, window corners; the hairline in the footer
};
// col(id): a colour linked to its palette entry, with the entry's hex beside the id.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// main-color is the engine's default accent: the dashes of the list take it.
const colorPalette = Object.entries({ ...palette, 'main-color': palette.brand })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// DIN 5008, form B: every position in mm from the sheet's top-left corner.
const DIN = {
left: 25, right: 20, top: 27, bottom: 30, // the margins of the text
field: { x: 20, y: 45, w: 85, h: 45 }, // the address field, behind the envelope window
notes: 17.7, // the field's top zone, for the return line; the address zone takes the rest
info: { x: 125, y: 50, w: 75 }, // the information block
folds: [105, 210], punch: 148.5, // fold marks for a DL envelope, and the punch mark
};
const TEXT = 210 - DIN.left - DIN.right; // 165 mm of text width
const WINDOW = DIN.field.w - 2 * (DIN.left - DIN.field.x); // 75 mm: text inset 5 mm each side
const PT = 25.4 / 72; // mm per point
const [LEAD, ROW] = [15, 12]; // pt: the body's leading, a row of the information block
// Design text is centred by default, and a header or footer line ends in '…': left, wrapped.
const text = (id, content, face, placement, more) => ({ kind: 'text', id, content,
align: 'left', overflow: 'wrap', ...face, placement, ...more }); // more: pages, align
const rule = (id, colour, placement, direction = 'horizontal') => ({ kind: 'rule', id,
direction, thickness: pt(0.5), color: col(colour), placement });
const face = (fontFamily, size, fontWeight, colour, more) => ({ fontFamily, fontSize: pt(size),
fontWeight, color: col(colour), ...more });
const FACE = { // lineHeight: a dimension is the line's depth, a number multiplies the size
label: face('Reddit Mono', 7, 400, 'muted', { lineHeight: pt(ROW) }),
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)
Pitfalls
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 →
{totalPages}counts the pages of the whole document, so with two letters in one Markdown file the second sheet of the first letter would read “Seite 2 von 4”. Build each letter on its own.
Credits
- Recipe
- Ignacio Ferro
- Text
- Original prose, CC BY 4.0
- Fonts
- Nunito Sans (SIL OFL 1.1) · Familjen Grotesk (SIL OFL 1.1) · Reddit Mono (SIL OFL 1.1)
Edit this write-up ↗ (opens in a new tab)Recipe folder on GitHub ↗ (opens in a new tab)


