Zum Hauptinhalt springen
Rezept Nummer 100

Rezepte · Kapitel 10 · Ausgabe und Integration

Ein gesetztes Buch auf dem Schreibtisch, in 3D

createFolioFromDocument aus dem Paket postext-folio öffnet ein gesetztes Kapitel als leinengebundenes Buch auf einem Nussbaumtisch, gestaltet über config.folio.

Auf dieser Seite
Stufe
Mittel
Postext
Getestet mit Postext 1.65.0
Erfordert ≥ 1.25.0
Lizenz
Aktualisiert am 10. Okt. 2026
Code MIT · Text CC BY 4.0

S. 1 von 4

  • Englisches Beispiel: noch keine deutsche Ausgabe
  • Endformat 129 × 198 mm
  • 1 Spalte
  • Literata 9,8/14
  • Fraunces
  • Work Sans
  • 4 Seiten
  • Stufe
  • Postext 1.57.1
  • In 49 ms gesetzt
  • 119 Zeilen Code

Kurz gesagt

Das erste Kapitel eines kurzen Romans, gezeigt als echtes Buch, das aufgeschlagen auf einem Schreibtisch liegt. Sie blättern die Seiten mit der Maus um, und Papier, Einband und Tisch werden in den Einstellungen gewählt.

Was Sie setzen

Das erste Kapitel von The Ferryman’s Ledger, einem kurzen Roman auf einem Format von 129 × 198 mm, als Buch auf einem Nussbaumtisch aufgeschlagen. Die Decke ist flaschengrünes Leinen, die Seiten sind ein voluminöses cremefarbenes Romanpapier, und der Leser fasst die rechte Seite an ihrer Kante und blättert sie um, wobei sich das Blatt wölbt und seinen Schatten auf die Seite darunter wirft. Der Text wird einmal mit buildDocument gesetzt; ein Aufruf des Pakets postext-folio macht aus diesem Satz das Buch. Alles, woraus das Buch besteht (Papier, Bindung, Tisch, Licht, Blickwinkel), ist Teil der Konfiguration, sodass dasselbe Dokument sein Aussehen in den Tab Folio der Sandbox mitnimmt.

Dieses Rezept beantwortet

  • Wie zeige ich mein Dokument als 3D-Buch, dessen Seiten der Leser von Hand umblättert?
  • Wie sehe ich Bindung, Umschlag, Papier und Beleuchtung eines Buchs vor dem Druck in der Vorschau?

Die kurze Antwort

script.js · Zeilen 174–185im vollständigen Code
const stage = document.createElement('section');
stage.id = 'folio';
stage.ariaLabel = 'The book in 3D';
stage.style.cssText = 'height: min(78vh, 720px); margin: 0 auto; max-width: 1280px';
document.getElementById('pages').before(stage);
createFolioFromDocument(stage, doc, {
  // The paper, binding, desk and light come from doc.config.folio. Only the photographed
  // desk is the host's choice: without textureBaseUrl the walnut is drawn procedurally.
  appearance: { textureBaseUrl: 'https://postext.dev/folio/textures' },
  onChange: ({ pages }) => kitStatus(`${doc.pages.length} pages · open at `
    + pages.map((i) => doc.pages[i].pageLabel || i + 1).join('–')),
});

Zutaten

Schrift
Literata, Fraunces, Work Sans (SIL OFL 1.1)
Dateien
Keine: Jedes Bild wird im Code gezeichnet

Zubereitung

#1 · Angeben, woraus das Buch besteht

script.js · Zeilen 34–41im vollständigen Code
const folio = {
  tilt: 26, // degrees from straight above: enough to see the depth of the page block
  paper: { type: 'bookWove', grammage: 70, shade: col('cream') }, // a bulky cream novel paper
  binding: { type: 'hardcover', cover: 'case', coverMaterial: 'cloth',
    coverColor: col('accent') }, // the case wraps the pages; boards a little larger
  surface: { type: 'walnut' },
  lighting: { environment: 'studio', intensity: 1, shadows: true },
};

config.folio wertet nur der 3D-Betrachter aus: Layout, Canvas, PDF und HTML-Ausgabe ignorieren es, sodass ein anderes Papier nie eine Zeile verschiebt. bookWove ist ein voluminöses Romanpapier, und 70 g/m² bei diesem Volumen ergeben ein Blatt von etwa 112 µm Dicke; der Betrachter multipliziert das mit der Seitenanzahl für die Tiefe des Buchblocks. Die Leinenfarbe ist mit dem Akzent der Palette verknüpft, demselben Grün wie Dachzeile und Paginas.

#2 · Ein ruhiger Auftakt und Kolumnentitel

script.js · Zeilen 45–57im vollständigen Code
const opener = { enabled: true, minHeight: mm(50), slot: { elements: [
  { kind: 'text', id: 'kicker', content: '{attr.kicker}', fontFamily: 'Work Sans',
    fontSize: pt(7.5), fontWeight: 600, letterSpacing: pt(1.5), textTransform: 'uppercase',
    color: col('accent'), align: 'left',
    placement: { anchor: { to: 'container', edge: 'top-left' }, offset: { y: mm(10) } } },
  { kind: 'text', id: 'title', content: '{titleText}', fontFamily: 'Fraunces', fontSize: pt(28),
    lineHeight: 1.05, fontWeight: 600, color: col('ink'), align: 'left', overflow: 'wrap',
    placement: { anchor: { to: '#kicker', edge: 'below' }, offset: { y: mm(3) },
      size: { width: mm(90) } } },
  { kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(1.25), color: col('accent'),
    placement: { anchor: { to: '#title', edge: 'below' }, offset: { y: mm(4.5) },
      size: { width: mm(12) } } },
] } };

Das Kapitel beginnt ein Drittel unterhalb des Kopfes einer rechten Seite, unter einer Dachzeile aus den Attributen der Überschrift. In 3D wirkt ein abgesenkter Auftakt wie in einem gedruckten Roman: Der Weißraum am Kopf der Seite ist das Erste, was der Leser beim Aufschlagen der Decke sieht.

script.js · Zeilen 61–74im vollständigen Code
const head = (id, content, parity, edge, x, extra = {}) => ({ kind: 'text', id, content, parity,
  pages: 'body', fontFamily: 'Work Sans', fontSize: pt(7), fontWeight: 500,
  letterSpacing: pt(1.1), textTransform: 'uppercase', color: col('muted'),
  placement: { anchor: { to: 'page', edge }, offset: { x: mm(x), y: mm(11) } }, ...extra });
const folioNumber = { fontWeight: 600, color: col('accent') };
const header = { elements: [
  head('verso-folio', '{pageNumber}', 'even', 'top-left', OUTER, folioNumber),
  head('verso-author', '{author}', 'even', 'top-left', OUTER + 8),
  head('recto-title', '{title}', 'odd', 'top-right', -(OUTER + 8)),
  head('recto-folio', '{pageNumber}', 'odd', 'top-right', -OUTER, folioNumber),
] };
const footer = { elements: [head('drop-folio', '{pageNumber}', 'all', 'bottom', 0,
  { ...folioNumber, pages: 'opener', placement: { anchor: { to: 'page', edge: 'bottom' },
    offset: { y: mm(-11) } } })] };

#3 · Das Dokument als Buch öffnen

Der Code steht oben in der kurzen Antwort. createFolioFromDocument nimmt einen Container und das gesetzte Dokument: Es malt jede Seite mit renderPageToCanvas in der genauen Größe eines Seitenplatzes, nur rund um die aufgeschlagene Doppelseite, und passt das Buch in den Container ein. Der Container braucht eine eigene Höhe, sonst hat das Buch keinen Platz. textureBaseUrl zeigt auf die fotografierten Tische auf postext.dev; ohne diese Angabe wird der Nussbaum mit prozeduralen Texturen gezeichnet.

Das ganze Rezept

Sandbox
// ═══ Postext Cookbook · Nº 100 · A laid-out book on the desk, in 3D ═══════════════════
// https://postext.dev/en/cookbook/folio-book-on-a-desk
// Code: MIT · Text: original (CC BY 4.0) · Pictures: none
// Fonts: Literata, Fraunces, Work Sans (SIL OFL 1.1) · Needs postext ≥ 1.25.0
//
// A chapter of a short novel, laid out on a trade-book page and opened with postext-folio as a
// cloth-bound book lying on a walnut desk. Take the right-hand page by its edge and drag it
// over, click a page, or use the arrow keys. The flat pages follow under the book.
import { buildDocumentWithFonts, renderPageToCanvas } from 'https://esm.sh/postext';
import { createFolioFromDocument } from 'https://esm.sh/postext-folio';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'folio-book-on-a-desk';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: semantic colours, every one linked by id
const palette = {
  ink: '#211d1a', // text: a warm near-black
  accent: '#2f5d50', // bottle green: kicker, rule, folios, and the cloth of the case
  rule: '#c9bfae', // the colophon's hairline
  muted: '#6d655c', // running heads and the colophon
  cream: '#f7f0e1', // the book wove the pages are printed on (the 3D paper only)
};
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' } })),
  { id: 'main-color', name: 'accent (defaults)', value: { hex: palette.accent, model: 'hex' } },
];
// #endregion
const [TRIM_W, TRIM_H, TOP, BOTTOM, INNER, OUTER] = [129, 198, 20, 22, 17, 15]; // mm: B-format
const LEAD = 14; // pt: the body leading

// #region folio: what the book is made of and where it lies; layout never reads it
const folio = {
  tilt: 26, // degrees from straight above: enough to see the depth of the page block
  paper: { type: 'bookWove', grammage: 70, shade: col('cream') }, // a bulky cream novel paper
  binding: { type: 'hardcover', cover: 'case', coverMaterial: 'cloth',
    coverColor: col('accent') }, // the case wraps the pages; boards a little larger
  surface: { type: 'walnut' },
  lighting: { environment: 'studio', intensity: 1, shadows: true },
};
// #endregion

// #region opener: a sunk chapter opening, kicker, title and a short rule
const opener = { enabled: true, minHeight: mm(50), slot: { elements: [
  { kind: 'text', id: 'kicker', content: '{attr.kicker}', fontFamily: 'Work Sans',
    fontSize: pt(7.5), fontWeight: 600, letterSpacing: pt(1.5), textTransform: 'uppercase',
    color: col('accent'), align: 'left',

Das zusammengesetzte script.js läuft unverändert: Fügen Sie es in das Modulskript einer beliebigen Seite ein, oder öffnen Sie das Rezept auf CodePen. Ordner des Rezepts auf GitHub ↗ (öffnet sich in einem neuen Tab)

Varianten

#Ein Taschenbuch auf Eiche bei Tageslicht

Ändern Sie drei Einstellungen, und dasselbe Kapitel ist ein Softcover auf einem hellen Tisch; nichts wird neu gesetzt.

-  binding: { type: 'hardcover', cover: 'case', coverMaterial: 'cloth',
-    coverColor: col('accent') }, // the case wraps the pages; boards a little larger
-  surface: { type: 'walnut' },
-  lighting: { environment: 'studio', intensity: 1, shadows: true },
+  binding: { type: 'paperback', cover: 'case', coverMaterial: 'paper',
+    coverColor: col('accent') },
+  surface: { type: 'oak' },
+  lighting: { environment: 'daylight', intensity: 1, shadows: true },

#Jedes Blatt auf einem anderen Papier

Ein Papiermusterbuch zeigt jedes Blatt mit :::paper auf einem eigenen Papier, und der Prüfstand für die Einstellungen ändert jede Einstellung live mit setAppearance.

Häufige Fehler

Häufiger Fehler

Der Folio-Betrachter übernimmt die Größe seines Containers

createFolioFromDocument passt das Buch in das Element ein, das Sie übergeben, mit den Schaltflächen und der Seitenzahl in seinen Rändern. Ein Element ohne Höhe (ein leeres div im normalen Fluss) zeigt nichts: Geben Sie ihm in CSS eine Höhe. 3D-Buchbetrachter (Folio) →

Nachweise

Text
Eigener Text, CC BY 4.0
Schriften
Literata (SIL OFL 1.1) · Fraunces (SIL OFL 1.1) · Work Sans (SIL OFL 1.1)
Sandbox