Skip to main content
Recipe number 195

Cookbook · Chapter 10 · Output & integration

A tunnel book twenty leaves deep

Nineteen round windows cut with dieCuts, each smaller than the last on one axis, so the cover looks through twenty painted planes of a wood to a deer at a pool.

On this page
Postext
Tested with Postext 1.84.0
Needs ≥ 1.84.0 · postext-pdf ≥ 1.84.0
Licence
Updated 13 Nov 2026
Code MIT · Text CC BY 4.0
  • Trim 150 × 150 mm
  • 1 column
  • Cormorant Garamond 14/17
  • Lora
  • 40 pages
  • Level
  • Postext 1.84.0
  • Laid out in 6 ms
  • 166 lines of code

In short

A thick board book about a walk in a wood. Every leaf has a round hole a little smaller than the one before, so from the cover you see all the way to the last page.

What you'll build

Into the Wood, a tunnel book of twenty board leaves on a 150 mm square. Each recto is one plane of a painted wood (oaks, foxgloves, a robin, a fox in the bracken, an owl, birches), and each is cut with a round window a little smaller than the one before, all on the same centre. The last plane is whole: a doe and her fawn at a pool in a clearing. From the cover the eye goes through all nineteen windows to the deer, and the cut edges of the board stand round the tunnel like the trunks themselves. On the back of every leaf a line of verse names the plane that faces it. The press file carries every window on the die plate.

This recipe answers

  • How do I make a tunnel book whose holes go twenty pages deep?
  • How do I send the die-maker a die line on its own plate in the PDF?

The short answer

script.js · lines 38–50in full code
// Leaf k (pages 2k − 1 and 2k) is cut with a circle of radius R1 · Q^(k − 1) round the
// same centre: 58 mm on the cover down to 12 mm on leaf 19. Leaf 20, the clearing, is
// whole, so from the cover the eye goes through nineteen windows to the far plane.
const [CX, CY, R1, Q] = [75, 66, 58, 0.9162];
const radius = (k) => R1 * Q ** (k - 1);
const leaves = Array.from({ length: 19 }, (_, i) => i + 1);
const dieCuts = {
  shapes: leaves.map((k) => ({ id: `w${k}`, name: `${t({ en: 'Window', es: 'Ventana' })} ${k}`,
    shape: 'circle', x: mm(CX - radius(k)), y: mm(CY - radius(k)),
    width: mm(2 * radius(k)), height: mm(2 * radius(k)) })),
  pages: leaves.map((k) => ({ pages: String(2 * k - 1), die: `w${k}` })), // recto of leaf k
  corners: { radius: mm(4), edges: 'fore' },
};

Nineteen windows, each smaller than the last, all on one axis

Ingredients

Type
Cormorant Garamond, Lora (SIL OFL 1.1)
Assets
  • plane01.jpg
  • plane02.jpg
  • plane03.jpg
  • plane04.jpg
  • plane05.jpg
  • plane06.jpg
  • plane07.jpg
  • plane08.jpg
  • plane09.jpg
  • plane10.jpg
  • plane11.jpg
  • plane12.jpg
  • plane13.jpg
  • plane14.jpg
  • plane15.jpg
  • plane16.jpg
  • plane17.jpg
  • plane18.jpg
  • plane19.jpg
  • plane20.jpg
  • Plane 1 of the wood (Generated With Diffusion Models, original)
  • Plane 2 of the wood (Generated With Diffusion Models, original)
  • Plane 3 of the wood (Generated With Diffusion Models, original)
  • Plane 4 of the wood (Generated With Diffusion Models, original)
  • Plane 5 of the wood (Generated With Diffusion Models, original)
  • Plane 6 of the wood (Generated With Diffusion Models, original)
  • Plane 7 of the wood (Generated With Diffusion Models, original)
  • Plane 8 of the wood (Generated With Diffusion Models, original)
  • Plane 9 of the wood (Generated With Diffusion Models, original)
  • Plane 10 of the wood (Generated With Diffusion Models, original)
  • Plane 11 of the wood (Generated With Diffusion Models, original)
  • Plane 12 of the wood (Generated With Diffusion Models, original)
  • Plane 13 of the wood (Generated With Diffusion Models, original)
  • Plane 14 of the wood (Generated With Diffusion Models, original)
  • Plane 15 of the wood (Generated With Diffusion Models, original)
  • Plane 16 of the wood (Generated With Diffusion Models, original)
  • Plane 17 of the wood (Generated With Diffusion Models, original)
  • Plane 18 of the wood (Generated With Diffusion Models, original)
  • Plane 19 of the wood (Generated With Diffusion Models, original)
  • Plane 20 of the wood (Generated With Diffusion Models, original)

Method

#1 · Nineteen windows on one axis

The code is the short answer above. The windows are built in a loop: leaf k gets a circle of radius R1 · Q^(k − 1) round the same centre, and dieCuts.pages puts it on page 2k − 1, the recto of that leaf. A hole cuts both sides of its leaf, so the verso behind it has the same window, mirrored. Q = 0.9162 takes 58 mm down to 12 mm in eighteen steps, and the last window is just wide enough for the deer.

#2 · Planes in register with their windows

script.js · lines 54–71in full code
// The plane pictures were scaled so each painting's opening meets its window, centred on
// (CX, CY), over a softened copy of itself; the window's centre is flat, the die takes it.
const SHEET = { width: mm(TRIM + 2 * BLEED), height: mm(TRIM + 2 * BLEED) };
const painting = { kind: 'image', id: 'painting', resourceId: '{attr.picture}', fit: 'cover',
  placement: at('page', 'top-left', -BLEED, -BLEED, SHEET) };
const full = (elements) => ({ enabled: true, minHeight: mm(TRIM - TOP), slot: { elements } });
const plate = { kind: 'box', id: 'plate', placement: at('page', 'top-left', 25, 129,
  { width: mm(100), height: mm(17) }), style: { backgroundColor: col('forest') } };
const line = (id, content, y, size, color, extra) => ({ kind: 'text', id, content,
  fontFamily: DISPLAY, fontSize: pt(size), lineHeight: 1.1, color: col(color),
  align: 'center', placement: at('page', 'top-left', 25, y, { width: mm(100) }), ...extra });
const headingStyles = [
  { id: 'cover', numbered: false, toc: false, advancedDesign: full([painting, plate,
    line('title', '{title}', 131, 21, 'cream', { fontWeight: 600 }),
    line('subtitle', '{subtitle}', 139.5, 10.5, 'moss', { italic: true })]) },
  { id: 'plane', numbered: false, breakBefore: { enabled: true, parity: 'odd' },
    advancedDesign: full([painting]) },
];

Each painting has its own misty opening, so the pictures were scaled before they went into the book: on each one the radius where leaves cover half the ring was measured in pixels, and the painting was scaled until that radius met the leaf's window, on the window's centre. Seen from the cover, every plane shows only a thin ring of its leaves round its window, and the rings stack into a tunnel. The centre each die takes away is flat, so it costs almost nothing in the file.

#3 · Nineteen circles on the Die plate

script.js · lines 83–84in full code
  print: { standard: 'pdfx4', outputProfile: 'fogra51', convertImages: false,
    dieLine: { output: 'page', ink: 'Die', width: pt(0.5) } },

The PDF strokes each window, and each leaf with its rounded fore-edge corners, on a Die separation that overprints and is never inked. Forty pages of paintings stay under 1.5 MB with convertImages: false.

#4 · The tunnel in the hand

script.js · lines 99–105in full code
  folio: {
    tilt: 40, yaw: -30,
    paper: { type: 'board', shade: '#f4ecd6' },
    binding: { type: 'hardcover', cover: 'pages', coverMaterial: 'paper' },
    surface: { type: 'oak' },
    lighting: { environment: 'daylight', intensity: 1.1 },
  },

Twenty leaves of board make a thick block, and Folio cuts every window through it: the closed book shows the tunnel with the walls of the cut stepping down to the clearing.

#5 · Twenty planes on a flat page

script.js · lines 250–260in full code
// `beneath` paints the page two on, which paints the page two on from it, and so on to
// the clearing: page 1 shows all twenty planes. Each canvas is painted once and reused.
const under = new Map();
const beneath = (i) => {
  if (!under.has(i) && doc.pages[i]) {
    const canvas = document.createElement('canvas');
    under.set(i, canvas);
    renderPageToCanvas(doc.pages[i], doc, canvas, { scale: 1, beneath });
  }
  return under.get(i);
};

beneath paints the page two on with its own beneath, so the cover's window shows page 3, whose window shows page 5, and so on down to page 39. Each page is painted once and reused, and the flat cover shows the same tunnel as the book.

The whole recipe

Sandbox
// ═══ Postext Cookbook · Nº 195 · A tunnel book twenty leaves deep ═══════════════════════
// https://postext.dev/en/cookbook/forest-tunnel-book
// Code: MIT · Text: original (CC BY 4.0) · Paintings: generated with diffusion models
// Fonts: Cormorant Garamond, Lora (SIL OFL 1.1) · Needs postext ≥ 1.84.0
//
// Twenty board leaves, each printed with one plane of a wood and cut with a round window a
// little smaller than the one before. From the cover you look down the whole tunnel, past
// oaks, foxgloves, an owl and a fox, to a doe and her fawn at a pool in the clearing.
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
import { createFolioFromDocument } from 'https://esm.sh/postext-folio';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'forest-tunnel-book';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: a deep forest green behind the words, cream type
const palette = {
  forest: '#1c2a1e', // the versos, and the plate under the cover title
  cream: '#f4ecd6', // all the type
  moss: '#a9b98a', // the subtitle and the colophon
};
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: 'moss (defaults)', value: { hex: palette.moss, model: 'hex' } },
];
// #endregion
const [TRIM, BLEED] = [150, 3]; // mm: a square board book, and its bleed
const [TOP, SIDE] = [128, 14]; // the words on each verso sit under its window
const [DISPLAY, TEXT] = ['Cormorant Garamond', 'Lora'];
const at = (to, edge, x = 0, y = 0, size) => ({ anchor: { to, edge },
  offset: { x: mm(x), y: mm(y) }, ...(size && { size }) });

// #region answer: nineteen windows, each smaller than the last, all on one axis
// Leaf k (pages 2k − 1 and 2k) is cut with a circle of radius R1 · Q^(k − 1) round the
// same centre: 58 mm on the cover down to 12 mm on leaf 19. Leaf 20, the clearing, is
// whole, so from the cover the eye goes through nineteen windows to the far plane.
const [CX, CY, R1, Q] = [75, 66, 58, 0.9162];
const radius = (k) => R1 * Q ** (k - 1);
const leaves = Array.from({ length: 19 }, (_, i) => i + 1);
const dieCuts = {
  shapes: leaves.map((k) => ({ id: `w${k}`, name: `${t({ en: 'Window', es: 'Ventana' })} ${k}`,
    shape: 'circle', x: mm(CX - radius(k)), y: mm(CY - radius(k)),
    width: mm(2 * radius(k)), height: mm(2 * radius(k)) })),
  pages: leaves.map((k) => ({ pages: String(2 * k - 1), die: `w${k}` })), // recto of leaf k

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

#Rounded square windows

A roundRect with a corner radius a third of its half-width gives a softer, cut-paper look.

-    shape: 'circle', x: mm(CX - radius(k)), y: mm(CY - radius(k)),
+    shape: 'roundRect', radius: mm(radius(k) / 3), x: mm(CX - radius(k)), y: mm(CY - radius(k)),

#Round every corner

A board book for small hands rounds all four corners of every leaf.

-  corners: { radius: mm(4), edges: 'fore' },
+  corners: { radius: mm(8), edges: 'all' },

Credits

Text
  • The verse of the walk and the colophon · Postext Cookbook · CC BY 4.0
Images
  • Plane 1 of the wood · Generated With Diffusion Models · original
  • Plane 2 of the wood · Generated With Diffusion Models · original
  • Plane 3 of the wood · Generated With Diffusion Models · original
  • Plane 4 of the wood · Generated With Diffusion Models · original
  • Plane 5 of the wood · Generated With Diffusion Models · original
  • Plane 6 of the wood · Generated With Diffusion Models · original
  • Plane 7 of the wood · Generated With Diffusion Models · original
  • Plane 8 of the wood · Generated With Diffusion Models · original
  • Plane 9 of the wood · Generated With Diffusion Models · original
  • Plane 10 of the wood · Generated With Diffusion Models · original
  • Plane 11 of the wood · Generated With Diffusion Models · original
  • Plane 12 of the wood · Generated With Diffusion Models · original
  • Plane 13 of the wood · Generated With Diffusion Models · original
  • Plane 14 of the wood · Generated With Diffusion Models · original
  • Plane 15 of the wood · Generated With Diffusion Models · original
  • Plane 16 of the wood · Generated With Diffusion Models · original
  • Plane 17 of the wood · Generated With Diffusion Models · original
  • Plane 18 of the wood · Generated With Diffusion Models · original
  • Plane 19 of the wood · Generated With Diffusion Models · original
  • Plane 20 of the wood · Generated With Diffusion Models · original
Fonts
Cormorant Garamond (SIL OFL 1.1) · Lora (SIL OFL 1.1)
SandboxPDF