In short
A small paperback of two Spanish legends, and the printer's sheet for its cover: back, spine, front and the two folded flaps, all in one piece. The spine is as wide as the pages are thick, so it is worked out from the book itself.
What you'll build
Two of Bécquer's legends, The Spirits' Mountain and The Emerald Eyes, as a pocket paperback of 120 × 190 mm with 60 mm flaps, and the sheet its cover is printed on. Postext lays out the 37 pages first: half title, title page, rights, contents, a title leaf for each legend, then the text in Crimson Pro 11/15.2. buildCover then takes those pages and builds the sheet: back flap, back cover with the blurb and the barcode, spine, front cover with a painting of a ruined chapel under the Moncayo, and front flap. The title, subtitle and author come from the book's metadata, and the flaps' text from a Markdown file of its own.
This recipe answers
- How do I make the cover sheet of a paperback with flaps, with the spine worked out from the page count?
The short answer
// The book's own binding profile: PUR perfect binding in 16-page signatures, flaps of
// 60 mm whatever the trim. The spine is written nowhere: buildCover works it out from the
// laid-out pages, rounded up to whole signatures, on the paper of `folio.paper`.
const production = {
bindings: [{ id: 'pur-flaps', name: 'PUR perfect binding, 60 mm flaps', style: 'perfect',
signature: 16, measures: { flapWidth: 60, bleed: 3, spineAllowance: 0.5 } }],
versions: [{ id: 'paperback', name: t({ en: 'Paperback', es: 'Rústica' }), binding: 'pur-flaps',
flaps: true, isbn: '978-84-0000-196-4', isbnAddOn: '90000' }],
};
// 100 g/m² bulky cream wove at a bulk of 2.4: each leaf is 100 × 2.4 = 240 µm thick.
const folio = { paper: { type: 'bookWove', grammage: 100, bulk: 2.4, shade: '#f7f1e3' } };
// The design: a night ground over the whole sheet and the painting on the front, into the
// bleed at head and foot and up to the flap's fold. The texts come from the cover Markdown,
// the title, subtitle and author from the book's metadata.
const cover = {
background: col('night'),
elements: [{ id: 'art', kind: 'image', zone: 'front', x: 0, y: -3, width: 118, height: 196,
resourceId: 'moncayo', fit: 'cover' }],
verticalAlign: { back: 'middle' },
};
The paperback: a printer's binding with 60 mm flaps, its ISBN, its paper
Ingredients
- Features
- Print cover sheetPrint versions, ISBN and spineCovers, title pages and colophonsHeading stylesDesigned openersText, rules and boxes in page designsDocument metadataParagraph stylesTable of contentsRunning heads and foliosFigures and tables as resourcesSemantic colour palettePDF exportPages on a canvas
- Also uses
- Paper, binding, desk and light (Folio)Heading attributesPaper colourHeads by page roleFonts embedded in the PDFRunning heads per sectionUnnumbered chapters
- Type
- Crimson Pro, Cormorant Garamond, Josefin Sans (SIL OFL 1.1)
- Assets
moncayo-1100.jpg- The front cover: a ruined chapel under the Moncayo on All Souls’ Night, in oils (Generated With Diffusion Models, original)
Method
#1 · The binding gives the flaps, the paper gives the spine
The code is the short answer above. The binding profile says how the printer works: PUR perfect binding in 16-page signatures, 60 mm flaps, 3 mm bleed and 0.5 mm added to the spine for the glue. The version names the ISBN and its five-digit add-on; the ISBN is a sample number, assigned to no book. No measure of the spine is written anywhere. The 37 pages round up to three signatures, 48 pages or 24 leaves, and each leaf of 100 g/m² paper at a bulk of 2.4 is 240 µm thick: 24 × 0.24 + 0.5 gives a spine of 6.3 mm. By default a spine under 6 mm carries no lettering (spineText.minSpine), which is why the book is on bulky paper.
#2 · The pages come first
const [W, H, TOP, FOOT, INNER, OUTER, LEAD] = [120, 190, 20, 22, 18, 15.5, 15.2]; // mm, pt
const at = (to, edge, x, y, size) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) },
...(size && { size }) });
const text = (id, content, look, place) => ({ kind: 'text', id, content, align: 'center',
overflow: 'wrap', placement: place, ...look });
const face = (fontFamily, size, color, extra) => ({ fontFamily, fontSize: pt(size), color,
...extra });
const label = (size, color = col('muted')) => face('Josefin Sans', size, color, caps(size / 5));
const none = { header: { elements: [] }, footer: { elements: [] }, numbered: false, toc: false };
const design = (minHeight, elements) => ({ enabled: true, minHeight: mm(minHeight),
slot: { elements } });
const page = (parity) => ({ breakBefore: { enabled: true, parity } });
const rule = (id, y, to = 'page') => ({ kind: 'rule', id, direction: 'horizontal',
thickness: pt(0.6), color: col('accent'), placement: at(to, 'top', 0, y, { width: mm(10) }) });
const folioAt = (y, pages) => ({ elements: [text('f', '{pageNumber}',
{ ...face('Crimson Pro', 9, col('ink')), pages }, at('page', 'bottom', 0, y))] });
const serif = (size, extra) => face('Cormorant Garamond', size, col('ink'), extra);
const headingStyles = [
{ ...none, id: 'half-title', advancedDesign: design(60, [
text('t', '{title}', serif(17, { fontWeight: 500 }), at('page', 'top', 0, 62))]) },
{ ...none, ...page('odd'), id: 'title-page', advancedDesign: design(H - TOP - FOOT, [
text('t', '{title}', serif(27, { fontWeight: 600 }), at('page', 'top', 0, 46)),
text('s', '{subtitle}', serif(13, { italic: true }), at('page', 'top', 0, 58)),
rule('r', 67),
text('a', '{author}', label(8, col('accent')), at('page', 'top', 0, 72)),
text('tr', '{attr.translators}', face('Crimson Pro', 9.5, col('muted'), { italic: true }),
at('page', 'top', 0, 118, { width: mm(70) })),
text('i', '{attr.imprint}', label(7), at('page', 'bottom', 0, -26)),
]) },
// The rights at the foot of the verso, under a short rule.
{ ...none, ...page('even'), id: 'rights',
advancedDesign: design(92, [rule('r', 86, 'container')]) },
{ ...none, ...page('odd'), id: 'contents', advancedDesign: design(34, [
text('t', '{titleText}', label(8, col('accent')), at('container', 'top', 0, 14)),
rule('r', 21, 'container')]) },
// Each legend has a title leaf of its own (the contents point to it), then opens on the
// next recto, sunk 40 mm.
{ ...none, ...page('odd'), id: 'tale-title', toc: true, advancedDesign: design(90, [
text('k', '{attr.kicker}', serif(15, { fontWeight: 600, color: col('accent') }),
at('page', 'top', 0, 58)),
text('t', '{titleText}', serif(23, { fontWeight: 500 }), at('page', 'top', 0, 67)),
text('p', '{attr.place}', face('Crimson Pro', 10.5, col('muted'), { italic: true }),
at('page', 'top', 0, 79)),
rule('r', 88)]) },
{ ...page('odd'), id: 'tale', toc: false, advancedDesign: design(40, [
text('t', '{titleText}', serif(15, { fontWeight: 500, italic: true }),
at('container', 'top', 0, 16)),
rule('r', 25, 'container')]) },
{ ...none, ...page('any'), id: 'colophon', advancedDesign: design(70, [
rule('r', 60, 'container')]) },
];
const head = (id, content, parity) => text(id, content, { ...label(6.8), parity, pages: 'body' },
at('page', 'top', 0, 11));
The book block is an ordinary Postext document, and every page it has counts towards the spine. The front matter uses heading styles whose designs place the title, the rule and the imprint at fixed heights on the page. Each legend opens with a title leaf of its own (the one the contents point to) and starts again on the next recto, 40 mm down. Change the type size or the margins and the page count moves, and the spine follows on the next build.
#3 · The cover's type lives with the book's
const style = (id, fontFamily, size, lead, color, extra) => ({ id, fontFamily, fontSize: pt(size),
lineHeight: pt(lead), color, italicColor: color, firstLineIndent: mm(0), textAlign: 'left',
hyphenation: false, ...extra });
const caps = (tracking) => ({ fontWeight: 600, textTransform: 'uppercase',
letterSpacing: pt(tracking) });
const coverStyles = [
style('cover-title', 'Cormorant Garamond', 40, 40, col('bone'), { fontWeight: 600,
textAlign: 'center', marginTop: mm(12) }),
style('cover-subtitle', 'Cormorant Garamond', 15, 19, col('bone'), { italic: true,
textAlign: 'center' }),
style('cover-author', 'Josefin Sans', 8.5, 11, col('gold'), { ...caps(1.8),
textAlign: 'center', marginTop: pt(16) }),
style('cover-spine', 'Josefin Sans', 7.5, 9, col('bone'), { ...caps(1.2), textAlign: 'center' }),
style('cover-blurb', 'Crimson Pro', 10.5, 14.5, col('bone'), { marginBottom: pt(7) }),
style('cover-note', 'Crimson Pro', 10.5, 14.5, col('gold'), { italic: true }),
style('flap-head', 'Josefin Sans', 7.5, 10, col('gold'), caps(1.4)),
style('flap-text', 'Crimson Pro', 9.6, 13.2, col('bone'), { marginTop: pt(5) }),
];
The sheet is laid out with the book's configuration, so its paragraph styles sit in the same list as the rights and the colophon. cover-title, cover-subtitle, cover-author and cover-spine are the names buildCover gives the metadata it places, and cover-blurb, cover-note, flap-head and flap-text are named in the cover Markdown. The text on the night ground is set ragged, without hyphens, in the bone and gold of the palette.
#4 · The sheet is built from the laid-out pages
const built = buildCover({ config, version: 'paperback', pages: book.pages, markdown: coverText,
metadata: book.metadata, resources });
if (!('config' in built)) throw new Error(built.issues.map((i) => i.kind).join(', '));
// The barcode is the cover's own picture. Its digits name OCR-B, which no font server
// has: they are set in the label face, which the PDF embeds like the rest.
for (const [id, bytes] of Object.entries(built.files)) {
await loadSvg(id, new TextDecoder().decode(bytes)
.replace(/font-family="[^"]*"/g, 'font-family="Josefin Sans"'));
}
const sheet = await buildDocumentWithFonts(built.content, built.config, kitFonts(FONTS));
buildCover gets the pages, the metadata and the cover Markdown, a :::frame for the back and one for each flap. It returns a document that buildDocumentWithFonts lays out like any other, plus the barcode as an SVG file. The barcode's digits ask for OCR-B, which no font server has, so the pen sets them in Josefin Sans, a face the PDF already embeds. The PDF holds the 37 pages and then the sheet at its own size, which is the file a printer expects.
The whole recipe
// ═══ Postext Cookbook · Nº 196 · A paperback cover with flaps, spine from the pages ═══
// https://postext.dev/en/cookbook/paperback-cover-with-flaps
// Code: MIT · Text: Bécquer, tr. C. F. & K. L. Bates (public domain) · Art: diffusion models
// Fonts: Crimson Pro, Cormorant Garamond, Josefin Sans (SIL OFL 1.1) · Needs postext ≥ 1.92.0
//
// Two of Bécquer's legends as a 120 × 190 mm paperback with 60 mm flaps. Postext lays the
// pages out first; buildCover then makes the cover sheet from them, its spine as thick as
// the pages on their paper.
import {
buildDocumentWithFonts, renderPageToCanvas, registerResourceImage, inlineSvgFonts,
} from 'https://esm.sh/postext';
import { buildCover } from 'https://esm.sh/postext/production';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'paperback-cover-with-flaps';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { ink: '#25221e', accent: '#86472a', muted: '#6b645a', paper: '#fbf7ee',
night: '#16242a', gold: '#c99b4e', bone: '#eee5d1' }; // the last three: the cover's
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' } },
];
// #region answer: the paperback: a printer's binding with 60 mm flaps, its ISBN, its paper
// The book's own binding profile: PUR perfect binding in 16-page signatures, flaps of
// 60 mm whatever the trim. The spine is written nowhere: buildCover works it out from the
// laid-out pages, rounded up to whole signatures, on the paper of `folio.paper`.
const production = {
bindings: [{ id: 'pur-flaps', name: 'PUR perfect binding, 60 mm flaps', style: 'perfect',
signature: 16, measures: { flapWidth: 60, bleed: 3, spineAllowance: 0.5 } }],
versions: [{ id: 'paperback', name: t({ en: 'Paperback', es: 'Rústica' }), binding: 'pur-flaps',
flaps: true, isbn: '978-84-0000-196-4', isbnAddOn: '90000' }],
};
// 100 g/m² bulky cream wove at a bulk of 2.4: each leaf is 100 × 2.4 = 240 µm thick.
const folio = { paper: { type: 'bookWove', grammage: 100, bulk: 2.4, shade: '#f7f1e3' } };
// The design: a night ground over the whole sheet and the painting on the front, into the
// bleed at head and foot and up to the flap's fold. The texts come from the cover Markdown,
// the title, subtitle and author from the book's metadata.
const cover = {
background: col('night'),
elements: [{ id: 'art', kind: 'image', zone: 'front', x: 0, y: -3, width: 118, height: 196,
resourceId: 'moncayo', fit: 'cover' }],
verticalAlign: { back: 'middle' },
};
// #endregion
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
#Letter the spine from top to bottom
English and American books read their spines from the top down; the default, bottom to top, is the Spanish and continental custom.
versions: [{ id: 'paperback', name: t({ en: 'Paperback', es: 'Rústica' }), binding: 'pur-flaps',
- flaps: true, isbn: '978-84-0000-196-4', isbnAddOn: '90000' }],
+ flaps: true, isbn: '978-84-0000-196-4', isbnAddOn: '90000',
+ spineText: { direction: 'topToBottom' } }],#Print on thinner paper
At 80 g/m² and a bulk of 2.2 a leaf is 176 µm, the spine drops to 4.7 mm and its lettering goes, since it needs 6 mm.
-const folio = { paper: { type: 'bookWove', grammage: 100, bulk: 2.4, shade: '#f7f1e3' } };
+const folio = { paper: { type: 'bookWove', grammage: 80, bulk: 2.2, shade: '#f7f1e3' } };Pitfalls
- The sheet comes after the book's pages in the captured list, so its page number is the book's page count plus one. Add a page to the book and the number changes.
- A barcode whose digits name a font the PDF cannot find fails at export. Load its SVG with a
font-familythe pen already has.
Credits
- Recipe
- Ignacio Ferro
- Text
- The Spirits’ Mountain and The Emerald Eyes, translated by Cornelia Frances Bates and Katharine Lee Bates, from Romantic Legends of Spain (1909), Project Gutenberg eBook #50044 · Gustavo Adolfo Bécquer · public domain
- El monte de las ánimas and Los ojos verdes, from the Obras (Madrid, Fernando Fe, 1885) as transcribed on Wikisource, accents modernised · Gustavo Adolfo Bécquer · public domain
- Images
- The front cover: a ruined chapel under the Moncayo on All Souls’ Night, in oils · Generated With Diffusion Models · original
- Fonts
- Crimson Pro (SIL OFL 1.1) · Cormorant Garamond (SIL OFL 1.1) · Josefin Sans (SIL OFL 1.1)
Edit this write-up ↗ (opens in a new tab)Recipe folder on GitHub ↗ (opens in a new tab)


