Vai al contenuto principale
Ricetta numero 58

Ricettario · Capitolo 1 · Pagina e griglia

Lettera commerciale secondo la DIN 5008

Un preventivo tedesco di due pagine su A4. L’oggetto è l’H1, la cui grafica fissa intestazione, indirizzo e blocco informativo dove vuole il modulo B.

In questa pagina
Output
Canvas · PDF
Livello
Intermedio
Postext
Provata con Postext 1.65.0
Richiede ≥ 1.34.0 · postext-pdf ≥ 1.34.0
Licenza
Aggiornata il 16 ott 2026
Codice MIT · Testo CC BY 4.0
  • Esempio in inglese: non c’è ancora un’edizione italiana
  • Formato 210 × 297 mm
  • 1 colonna
  • Nunito Sans 10,5/15
  • Familjen Grotesk
  • Reddit Mono
  • 2 pagine
  • Livello
  • Postext 1.57.1
  • Impaginato in 71 ms
  • 180 righe di codice

In breve

Un’offerta di prezzo di due pagine da un laboratorio tedesco di finestre. Mostra come collocare l’indirizzo e le altre parti di una lettera commerciale dove le mette la norma tedesca, perché entri in una busta a finestra.

Che cosa comporrai

La Fensterwerkstatt Tessin, un laboratorio berlinese inventato che restaura doppie finestre, manda un preventivo all’amministrazione di un condominio. Occupa due fogli A4 in tedesco, impaginati secondo il modulo B della DIN 5008. Una fascia blu di Berlino in testa contiene il logo e il nome del laboratorio. Sotto, ogni parte sta dove la mette la norma: la riga del mittente e l’indirizzo dentro il campo di 85 × 45 mm che si vede attraverso la finestra di una busta DL, il blocco informativo a 125 mm dal bordo sinistro, l’oggetto in grassetto due righe vuote sotto il campo, e i segni di piega e di foratura a 105, 148,5 e 210 mm. I dati aziendali corrono su tre colonne al piede di entrambi i fogli. Il secondo foglio ripete il riferimento accanto a «Seite 2 von 2» e finisce con una firma disegnata in codice.

Questa ricetta risponde a

  • Come fisso un badge o un adesivo in una posizione fissa della pagina?
  • Come aggiungo una filigrana, una tinta di fondo o un’immagine decorativa su ogni pagina?
  • Come nascondo le testatine nelle aperture e nelle pagine bianche, o coloro un verso bianco con il colore della parte?
  • Come compongo un’epigrafe, una dedica, una firma o una citazione in evidenza con una grande virgoletta?

La risposta breve

script.js · righe 59–78nel codice completo
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() }] });

Ingredienti

Tipo
Nunito Sans, Familjen Grotesk, Reddit Mono (SIL OFL 1.1)
Risorse
Nessuna: ogni immagine è disegnata nel codice

Preparazione

#1 · Fissa la prima pagina al foglio in millimetri

script.js · righe 59–78nel codice completo
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() ancora un elemento per il suo angolo superiore sinistro a 'page', il formato rifilato (collocazione degli elementi), quindi ogni x e y è una distanza dall’angolo del foglio e le misure della norma entrano invariate: l’indirizzo a 25 mm in orizzontale e 62,7 mm in verticale, la prima etichetta del blocco informativo a 125 e 50. Questi elementi formano la grafica dell’H1. Il testo del titolo è l’oggetto ({titleText}) e i suoi attributi contengono l’indirizzo e i riferimenti, così la configurazione contiene la carta da lettere e il Markdown contiene la lettera. L’oggetto, a 100,6 mm, è l’elemento più basso, quindi il titolo riserva il foglio fino al piede dell’oggetto. marginBottom aggiunge le due righe vuote, e il saluto iniziale comincia sulla linea di griglia successiva, a 117 mm.

L’indirizzo è un solo attributo con \n tra le righe, e ogni \n comincia una nuova riga nel testo del titolo grafico. Il titolo sta nella colonna di testo, eppure la sua grafica dipinge la fascia, il logo e il nome sopra il margine superiore di 27 mm, perché ogni elemento è fissato alla pagina.

#2 · Concatena il blocco informativo da un’unica etichetta fissata

script.js · righe 82–93nel codice completo
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) } }),
]);

Solo la prima etichetta è fissata al foglio. Ogni altra etichetta è ancorata 'below' a quella precedente, e ogni valore alla sua etichetta con 'align-top' e uno scostamento di 29 mm, così una riga aggiunta a INFO non ha bisogno di coordinate. Il testo dei titoli grafici mette la linea di base all’80% del riquadro della riga. L’etichetta in corpo 7 e il valore in corpo 9 impostano entrambi lineHeight: pt(ROW), una riga di 12 pt, così condividono la linea di base su ogni riga di 4,23 mm.

#3 · Disegna la carta intestata nello stesso progetto grafico

script.js · righe 97–118nel codice completo
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')];
  }),
];

La fascia è un riquadro fissato all’angolo del foglio. width: 'fill' la stende da un bordo all’altro, e la sua altezza di 32 mm la porta 5 mm oltre il margine superiore di 27 mm. Il logo è un elemento immagine che disegna una risorsa alta 18 mm e prende la larghezza dal disegno (elementi immagine). Il nome sta 'right-of' il logo, e la riga delle attività 'below' il nome. Otto filetti di 3 mm disegnano un angolo a ogni vertice del campo indirizzo di 85 × 45 mm, la parte del foglio che mostra la finestra della busta.

#4 · Metti nell’intestazione e nel piè di pagina ciò che hanno in comune tutti i fogli

script.js · righe 122–144nel codice completo
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) }))),
] };

Un elemento della grafica dell’H1 fissato sotto l’oggetto si aggiunge all’altezza che il titolo riserva. Con il segno di piega a 210 mm nella grafica, il saluto scende a 222,8 mm e la lettera arriva a tre pagine. L’intestazione si dipinge su ogni pagina e non riserva spazio, quindi i tre segni vanno lì (intestazioni e piè di pagina). La pagina 1 si apre con l’H1, il che la rende una pagina 'opener', così pages: 'body' limita la striscia blu, la riga del riferimento e Seite {pageNumber} von {totalPages} ai fogli che seguono. La riga del riferimento legge gli attributi dell’H1 tramite {attr.unser-zeichen} e {attr.datum}.

#5 · Componi la firma nel flusso

script.js · righe 148–157nel codice completo
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"} compone il disegno sotto «Mit freundlichen Grüßen», e width: 0.297 lo rende largo 49 mm e alto 21,1 mm, poco meno di quattro righe da 15 pt. Il testo dopo una risorsa nel flusso torna sulla griglia del corpo. A 0.25 il disegno era alto 17,8 mm, e i 3,4 mm che la griglia aggiungeva sotto allontanavano il nome dalla firma. Il tipo di risorsa ha un captionPrefix vuoto, e Postext non compone una didascalia quando sia il prefisso sia la didascalia sono vuoti, quindi sotto la firma non compaiono etichetta né numero (tipi di risorsa). Il logo è una risorsa dello stesso tipo, disegnata solo dall’elemento immagine. Nessun :ref o ::resource lo cita, quindi non entra mai nel flusso.

La ricetta completa

Sandbox
// ═══ 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) }),

Lo script.js composto funziona così com’è: incollalo nello script modulo di qualsiasi pagina, oppure apri la ricetta su CodePen. Cartella della ricetta su GitHub ↗ (si apre in una nuova scheda)

Errori frequenti

Errore frequente

Un’apertura riserva altezza fino al suo elemento ancorato alla pagina più basso

Un’apertura con progetto avanzato riserva l’altezza del suo elemento più basso, e contano anche gli elementi ancorati alla pagina o all’abbondanza sotto il titolo, quindi una decorazione al piede della pagina spinge il testo alla pagina successiva. Dai a un elemento del genere reserve: false (da postext 1.5): viene dipinto dove è ancorato e non riserva nulla. Gli elementi che seguono la fascia stessa (ancorati al suo piede, o alti 'fill') non ne determinano mai l’altezza. Aperture progettate →

Errore frequente

Gli elementi di intestazione e piè di pagina dipingono sopra il testo

Gli elementi di intestazione e piè di pagina vengono dipinti sopra la pagina e l’area del testo non fa loro spazio. Tienili entro i margini, che sono ciò che ne riserva lo spazio. Testatine e folio →

  • {totalPages} conta le pagine dell’intero documento, quindi con due lettere in un solo file Markdown il secondo foglio della prima lettera riporterebbe «Seite 2 von 4». Costruisci ogni lettera da sola.

Crediti

Testo
Testo originale, CC BY 4.0
Font
Nunito Sans (SIL OFL 1.1) · Familjen Grotesk (SIL OFL 1.1) · Reddit Mono (SIL OFL 1.1)
SandboxPDF