跳到主要内容
食谱编号199

排版食谱 · 第10章 · 输出与集成

烫金、局部上光加起凸的封面

曼里克《悼亡父诗》的平装本:画面上局部上光,书名框烫金并压在起凸的底板上,封底一枚素压菱形,每道工艺各有一块印版。

本页内容
类型
诗歌
输出
Canvas · PDF
难度
高级
Postext
已用Postext 1.92.0测试
需要≥ 1.92.0 · postext-pdf ≥ 1.92.0
许可证
更新于2026年11月23日
代码MIT · 文本CC BY 4.0

页码1 · 第28页,共28页

  • 英文样例:尚无中文版本
  • 成品尺寸125 × 200 mm
  • 1栏
  • Alegreya 11/15
  • Alegreya SC
  • Alegreya Sans SC
  • 28页
  • 难度
  • Postext 1.92.0
  • 排版用时163 ms
  • 250行代码

简单来说

一本薄薄的古典诗集,以及它的封面印张。封面印好以后还有几道工序:画面上一层亮光,书名外框烫金,有些图形从纸板上压凸出来。页面上画出了每道工序落在哪里。

成品一览

豪尔赫·曼里克为父亲之死写的《悼亡父诗》(Coplas),英文版用朗费罗的译本,西班牙文版排原文,排成125 × 200毫米的平装书,另外还有封面印张:四色印完以后,它要送去做表面工艺。印张上有三道工艺。书名框上下两段画面做局部亮光上光。书名框的双层边框烫金,框里的底板起凸,书名就落在凸起的面上。封底有一枚素压的菱形:不上墨,只把纸板压凸。书的下方,示例把印张画了四遍:印出来的样子、上光版和烫金版的假色图、侧光下的样子,以及刻版师据以做压凸模的起凸版。PDF是PDF/X-4,每道工艺一块印版。

这道食谱解答

  • 怎样给封面加局部光油、烫印和起凸的书名,交给印厂和装订厂?

简短回答

script.js · 第65–104行在完整代码中
// A slim paperback: PUR perfect binding, the spine from the pages on 120 g/m² wove. The
// spine is under the 6 mm a spine is lettered from by default, so this version letters it
// from 4.5 mm.
const production = {
  bindings: [{ id: 'pur', name: 'PUR perfect binding', style: 'perfect', signature: 16,
    measures: { bleed: 3, spineAllowance: 0.5 } }],
  versions: [{ id: 'paperback', name: t({ en: 'Paperback', es: 'Rústica' }), binding: 'pur',
    isbn: '978-84-0000-199-5', spineText: { minSpine: 4.5 } }],
};
const folio = { paper: { type: 'bookWove', grammage: 120, bulk: 2.2, shade: '#f7f1e3' } };
const cover = {
  background: col('ground'),
  elements: [
    { id: 'art', kind: 'image', zone: 'front', x: 0, y: -3, width: 128, height: 206,
      resourceId: 'river', fit: 'cover' },
    // The title's panel, a shade darker than the ground, and the frame round it. The frame
    // prints nothing in four colours (it has the panel's colour): the foil plate carries it.
    { id: 'panel', kind: 'shape', zone: 'front', x: 14, y: 77, width: CW, height: CH,
      color: col('panel'), path: [{ closed: true, nodes: contour(0, 6) }] },
    { id: 'cartouche', kind: 'shape', zone: 'front', x: 14, y: 77, width: CW, height: CH,
      color: col('panel'), path: cartouche },
  ],
  finishes: [
    // A spot gloss over the painting above and below the panel, 4 mm clear of it, so the
    // varnish never lies on the foil. The back and the spine stay matt.
    ...[[-3, 76], [127, 76]].map(([y, height], i) => ({ id: `gloss-${i + 1}`, process: 'varnish',
      ink: col('varnish'), shape: { box: { zone: 'front', x: 0, y, width: 128, height } } })),
    // Gold foil on the frame, and the whole panel embossed: the title prints on a raised
    // field, the foil stamped round its edge.
    { id: 'gold', process: 'foil', ink: col('foil'), shape: { element: 'cartouche' } },
    { id: 'relief', process: 'emboss', shape: { element: 'panel' } },
    // A blind emboss: no ink and no foil, only the paper raised.
    { id: 'emblem', process: 'emboss', shape: { outline: emblem,
      box: { zone: 'back', x: 52.5, y: 30, width: 20, height: 20 } } },
  ],
  verticalAlign: { front: 'middle', back: 'middle' },
};
// The press file: PDF/X-4. The varnish and the foil are spot inks with a finish, each on
// its plate; the emboss goes on a plate named Emboss, beside the die line.
const print = { standard: 'pdfx4', outputProfile: 'fogra51', convertImages: false };

用料

类型
Alegreya, Alegreya SC, Alegreya Sans SC(SIL OFL 1.1)
素材
  • river-1100.jpg
  • The cover painting: a river at sunset running to the sea below a ruined castle, in oils (Generated With Diffusion Models, 原创)

做法

#1 · 每道工艺都跟着设计里的一个图形

代码就是上面的简短回答。一道工艺写明工艺类型、要印的油墨(如果有)和一个形状:封面上的一个元素({ element: 'cartouche' })、某个区域里的一个方框,或者方框里的一条轮廓。上光和烫金是调色板里带finish的专色,所以在PDF里各有一块印版,印前检查会把它们列出来。起凸什么都不印。它放在一块技术版上,印刷文件把它叫作Emboss,是刻版师用的那块,页面上不画它。

上光是两个方框,一个在书名框上面,一个在下面,都离书名框4毫米,免得上光压到烫金。封底和书脊保持哑光。全书27页,用120 g/m²、松厚度2.2的书纸,按16页一帖装订后是32页,书脊4.7毫米。默认书脊不足6毫米不印字,所以版本里把spineText.minSpine设为4.5。这个ISBN是示例号码,不属于任何一本书。

#2 · 书名框是设计里的路径,不是图片

script.js · 第36–61行在完整代码中
// Fractions of its box, so the frame stretches with it. Two rings, each an outer contour and
// an inner one run the other way round: the hole between them stays empty, and the foil and
// the emboss take exactly this outline.
const [CW, CH] = [97, 46]; // the cartouche's box, mm
const K = 0.5523; // a quarter circle as a cubic
function contour(inset, notch) {
  const [tx, ty, rx, ry] = [inset / CW, inset / CH, (notch + inset) / CW, (notch + inset) / CH];
  // Each corner: the point on the edge before it and on the edge after it, a hollow arc
  // between them whose handles leave each edge square.
  const corners = [
    [[1 - rx, ty], [1 - tx, ry], 'h'], [[1 - tx, 1 - ry], [1 - rx, 1 - ty], 'v'],
    [[rx, 1 - ty], [tx, 1 - ry], 'h'], [[tx, ry], [rx, ty], 'v']];
  return corners.flatMap(([[ax, ay], [bx, by], edge]) => [
    { x: ax, y: ay, out: edge === 'h' ? { x: ax, y: ay + K * (by - ay) }
      : { x: ax + K * (bx - ax), y: ay } },
    { x: bx, y: by, in: edge === 'h' ? { x: bx - K * (bx - ax), y: by }
      : { x: bx, y: by - K * (by - ay) } }]);
}
const reversed = (nodes) => nodes.slice().reverse()
  .map(({ x, y, in: i, out: o }) => ({ x, y, ...(o && { in: o }), ...(i && { out: i }) }));
const ring = (outer, inner, notch) => [{ closed: true, nodes: contour(outer, notch) },
  { closed: true, nodes: reversed(contour(inner, notch)) }];
const cartouche = [...ring(0, 1.3, 6), ...ring(2.3, 2.75, 6)];
// The emblem on the back: a lozenge with a lozenge cut out of it, as a saved outline.
const lozenge = (d) => [[0.5, d], [1 - d, 0.5], [0.5, 1 - d], [d, 0.5]].map(([x, y]) => ({ x, y }));
const emblem = [lozenge(0), lozenge(0.24).reverse()];

烫金和起凸严格沿着所指元素的轮廓走,所以边框必须是一个引擎知道路径的图形。封面路径是一组闭合轮廓,节点用元素方框的比例表示,曲线带进出控制柄。每个角是向内凹的四分之一圆,用三次曲线画。一个环由外轮廓和反方向走的内轮廓组成:按nonzero规则,两者之间是空的。两个环就是双层边框。边框和底板同色,四色印刷时什么也不印,全靠烫金版。封底的徽记是存好的一条轮廓:两个菱形,小的那个反向。

#3 · 封面的样式

script.js · 第108–124行在完整代码中
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: 700, letterSpacing: pt(tracking) });
const mid = { textAlign: 'center' };
const coverStyles = [
  style('cover-title', 'Alegreya SC', 40, 40, col('cream'), { ...mid, fontWeight: 500 }),
  style('cover-subtitle', 'Alegreya', 13, 17, col('cream'), { ...mid, italic: true }),
  style('cover-author', 'Alegreya Sans SC', 9, 12, col('ochre'), { ...mid, ...caps(1.6),
    marginTop: pt(9) }),
  style('cover-spine', 'Alegreya Sans SC', 7, 8, col('cream'), { ...mid, ...caps(1.1) }),
  style('cover-quote', 'Alegreya', 13, 17, col('ochre'), { ...mid, italic: true,
    marginBottom: pt(16) }),
  style('cover-blurb', 'Alegreya', 10.5, 14.5, col('cream'), { marginBottom: pt(7) }),
  style('cover-note', 'Alegreya Sans SC', 8, 11, col('ochre'), { ...caps(1.2),
    marginTop: pt(4) }),
];

cover-title、cover-subtitle、cover-author和cover-spine是buildCover给它放置的元数据起的名字;cover-quote、cover-blurb和cover-note写在封面的Markdown里。封面在高度上居中(verticalAlign),书名不管字号多大都落在书名框里。

#4 · 书芯

script.js · 第128–167行在完整代码中
const [W, H, TOP, FOOT, INNER, OUTER, LEAD] = [125, 200, 22, 24, 19, 17, 15]; // 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, x) => ({ fontFamily, fontSize: pt(size), color, ...x });
const label = (size, color = col('muted')) => face('Alegreya Sans SC', size, color, caps(size / 6));
const sc = (size, extra) => face('Alegreya SC', size, col('ink'), { fontWeight: 500, ...extra });
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(12) }) });
const headingStyles = [
  { ...none, id: 'half-title', advancedDesign: design(60, [
    text('t', '{title}', sc(18), at('page', 'top', 0, 64))]) },
  { ...none, ...page('odd'), id: 'title-page', advancedDesign: design(H - TOP - FOOT, [
    text('t', '{title}', sc(34), at('page', 'top', 0, 50)),
    text('s', '{subtitle}', face('Alegreya', 13, col('ink'), { italic: true }),
      at('page', 'top', 0, 66)),
    rule('r', 76),
    text('a', '{author}', label(8.5, col('accent')), at('page', 'top', 0, 81)),
    text('c', '{attr.credit}', face('Alegreya', 9.5, col('muted'), { italic: true }),
      at('page', 'top', 0, 120, { width: mm(76) })),
    text('i', '{attr.imprint}', label(7.5), at('page', 'bottom', 0, -28)),
  ]) },
  { ...none, ...page('even'), id: 'rights',
    advancedDesign: design(92, [rule('r', 86, 'container')]) },
  // The poem opens on a recto, sunk 46 mm, its title in small capitals over a short rule.
  { ...page('odd'), id: 'poem', toc: false, header: { elements: [] }, advancedDesign: design(46, [
    text('t', '{titleText}', sc(19), at('container', 'top', 0, 18)),
    text('n', '{attr.note}', face('Alegreya', 10.5, col('muted'), { italic: true }),
      at('container', 'top', 0, 28, { width: mm(80) })),
    rule('r', 38, 'container')]) },
  { ...none, ...page('odd'), id: 'colophon', advancedDesign: design(64, [
    rule('r', 56, 'container')]) },
];
const head = (id, content, parity) => text(id, content, { ...label(6.8), parity, pages: 'body' },
  at('page', 'top', 0, 11));

半书名页、书名页、版权页,然后诗从一个右页开始,往下沉46毫米,按诗行排,不把一节拆到两页上。书眉左页是作者,右页是书名。版本记录放在最后一个右页上收尾。

#5 · 印张由排好的内页生成

script.js · 第858–866行在完整代码中
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's digits name OCR-B, which no font server has: the label face sets them.
for (const [id, bytes] of Object.entries(built.files)) {
  await loadSvg(id, new TextDecoder().decode(bytes)
    .replace(/font-family="[^"]*"/g, 'font-family="Alegreya Sans SC"'));
}
const sheet = await buildDocumentWithFonts(built.content, built.config, kitFonts(FONTS));

buildCover接收页面、元数据和封面的Markdown,返回一份交给buildDocumentWithFonts的文档,外加SVG格式的条码。条码数字要用OCR-B,没有哪个字体服务器提供,所以示例改用已经加载的Alegreya Sans SC。

#6 · 每块印版覆盖哪里

script.js · 第873–931行在完整代码中
// 'flat' paints the inks: the foil in its colour, the varnish and the emboss not at all.
// 'map' marks the special plates in false colour over a faded sheet, 'sheen' rakes a light
// across it. The emboss plate is drawn from the page's technical plates, the outlines the
// PDF fills on its Emboss separation.
const leaf = sheet.pages[0];
const scale = 1100 / leaf.width;
const outline = (ctx, paths) => {
  ctx.beginPath();
  for (const c of paths.flat()) {
    if (c.op === 'M') ctx.moveTo(c.x, c.y);
    else if (c.op === 'L') ctx.lineTo(c.x, c.y);
    else if (c.op === 'C') ctx.bezierCurveTo(c.x1, c.y1, c.x2, c.y2, c.x, c.y);
    else if (c.op === 'Q') ctx.quadraticCurveTo(c.x1, c.y1, c.x, c.y);
    else ctx.closePath();
  }
  ctx.fill('nonzero');
};
const VIEWS = [
  ['flat', t({ en: 'As it prints', es: 'Como se imprime' })],
  ['map', t({ en: 'The varnish and foil plates', es: 'Las planchas de barniz y oro' })],
  ['sheen', t({ en: 'Under a raking light', es: 'Con luz rasante' })],
  ['emboss', t({ en: 'The Emboss plate', es: 'La plancha de gofrado' })],
];
const views = document.createElement('section');
views.id = 'finish-views';
views.style.cssText = 'display: grid; grid-template-columns: repeat(2, minmax(0, 560px)); '
  + 'gap: 18px; justify-content: center; padding: 24px max(16px, calc(50% - 520px)); color: #ddd; '
  + 'font: 14px sans-serif';
for (const [mode, name] of VIEWS) {
  const [figure, canvas, caption] = ['figure', 'canvas', 'figcaption']
    .map((tag) => document.createElement(tag));
  figure.style.margin = '0';
  canvas.style.cssText = 'display: block; width: 100%';
  canvas.setAttribute('role', 'img');
  canvas.setAttribute('aria-label', `${t({ en: 'The cover sheet', es: 'El pliego' })}: ${name}`);
  renderPageToCanvas(leaf, sheet, canvas, { scale, finishes: mode === 'emboss' ? 'flat' : mode });
  if (mode === 'emboss') {
    // The die-maker's film: the plate in black on white, the sheet faded under it.
    const ctx = canvas.getContext('2d');
    ctx.setTransform(1, 0, 0, 1, 0, 0);
    ctx.fillStyle = 'rgba(255, 255, 255, 0.86)';
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    ctx.setTransform(scale, 0, 0, scale, 0, 0);
    ctx.fillStyle = '#111';
    outline(ctx, (leaf.plates ?? []).flatMap((p) => p.paths));
  }
  caption.textContent = name;
  figure.append(canvas, caption);
  views.append(figure);
}
// What the preflight reads from the sheet: its spot plates and the reliefs it checks.
const spots = preflightDocument(sheet).find((i) => i.kind === 'spotInks');
const list = document.createElement('p');
list.style.cssText = 'grid-column: 1 / -1; margin: 0; text-align: center';
list.textContent = `${t({ en: 'Plates beside CMYK', es: 'Planchas además de CMYK' })}: `
  + [...(spots?.inks ?? []), ...new Set((leaf.plates ?? [])
    .map((p) => `${p.process[0].toUpperCase()}${p.process.slice(1)}`))].join(' · ');
views.append(list);
document.getElementById('pages').before(views);

renderPageToCanvas有三种画工艺的方式。flat按印刷机落墨的样子画:烫金画成它的颜色,上光不画。map把印张调淡,用假色标出每块专色版。sheen让一道侧光扫过印张,上光和烫金会反光。起凸三种都不出现,因为它不印东西;第四幅图在调淡的印张上用黑色画出页面的技术版(page.plates),也就是PDF在Emboss分色上填充的轮廓。下面那一行从preflightDocument读出专色,从技术版读出工艺。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 199 · A cover in foil, spot varnish and emboss ═══════════════
// https://postext.dev/en/cookbook/cover-foil-varnish-emboss
// Code: MIT · Text: Manrique, tr. H. W. Longfellow (public domain) · Art: diffusion models
// Fonts: Alegreya, Alegreya SC, Alegreya Sans SC (SIL OFL 1.1) · Needs postext ≥ 1.92.0
//
// Manrique's Coplas as a slim paperback whose cover goes to the finisher after the press: a
// spot gloss over the painting, a gold-foil cartouche stamped over an emboss of the same
// shape, and a blind emboss on the back. Each finish is a shape of the cover's design; the
// varnish and the foil get spot plates of their own, the emboss a plate that prints nothing.
import { buildDocumentWithFonts, renderPageToCanvas, registerResourceImage, inlineSvgFonts,
  preflightDocument } 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 = 'cover-foil-varnish-emboss';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// The pages' four colours, then the cover's: a bottle-green ground and its darker panel.
const palette = { ink: '#262320', accent: '#8a3b2a', muted: '#6d655b', paper: '#fbf7ef',
  ground: '#1d2b27', panel: '#15201d', cream: '#efe5cf', ochre: '#c8a15a' };
// The two inks the finisher is asked for: spot colours that each make a plate of their own.
const spot = (hex, name, cmyk, kind) => ({ hex, model: 'spot',
  spot: { name, cmyk, finish: { kind, sheen: 'gloss' } } });
const inks = { foil: spot('#b8963e', 'Gold foil', { c: 0, m: 20, y: 60, k: 25 }, 'foil'),
  varnish: spot('#eef0e6', 'Gloss varnish', { c: 0, m: 0, y: 0, k: 0 }, 'varnish') };
const col = (id) => (inks[id] ? { ...inks[id], paletteId: id }
  : { hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [
  ...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
  ...Object.entries(inks).map(([id, value]) => ({ id, name: value.spot.name, value })),
  { id: 'main-color', name: 'accent (defaults)', value: { hex: palette.accent, model: 'hex' } },
];

// #region art: the cartouche, a frame with hollow corners, drawn as a shape of the design
// Fractions of its box, so the frame stretches with it. Two rings, each an outer contour and
// an inner one run the other way round: the hole between them stays empty, and the foil and
// the emboss take exactly this outline.
const [CW, CH] = [97, 46]; // the cartouche's box, mm
const K = 0.5523; // a quarter circle as a cubic
function contour(inset, notch) {
  const [tx, ty, rx, ry] = [inset / CW, inset / CH, (notch + inset) / CW, (notch + inset) / CH];
  // Each corner: the point on the edge before it and on the edge after it, a hollow arc
  // between them whose handles leave each edge square.
  const corners = [
    [[1 - rx, ty], [1 - tx, ry], 'h'], [[1 - tx, 1 - ry], [1 - rx, 1 - ty], 'v'],
    [[rx, 1 - ty], [tx, 1 - ry], 'h'], [[tx, ry], [rx, ty], 'v']];
  return corners.flatMap(([[ax, ay], [bx, by], edge]) => [

组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)

变化

#把徽记改成压凹

压凹把图形压进纸板,而不是顶起来,放在单独的Deboss版上。

-    { id: 'emblem', process: 'emboss', shape: { outline: emblem,
+    { id: 'emblem', process: 'deboss', shape: { outline: emblem,

#整幅画上光

画面元素上的一道工艺代替两个方框。这样上光也会盖过书名框和书名。

-    ...[[-3, 76], [127, 76]].map(([y, height], i) => ({ id: `gloss-${i + 1}`, process: 'varnish',
-      ink: col('varnish'), shape: { box: { zone: 'front', x: 0, y, width: 128, height } } })),
+    { id: 'gloss', process: 'varnish', ink: col('varnish'), shape: { element: 'art' } },

常见问题

  • 起凸或压凹离裁切线或折线不到3毫米,印前检查会报出来(reliefTrim、reliefFold):纸板在那里会裂。让凹凸远离书脊的折线。
  • 起凸在屏幕上从来不画。到PDF的Emboss分色里去看,或者像示例这样画出page.plates。
  • 工艺盖在文字框上,会遮住文字,视图里和印刷文件里都一样。留一部分文字在烫金之外,就像这里的书名放在书名框中间的空处。

致谢

文本
  • Coplas de Manrique, translated by Henry Wadsworth Longfellow (1833), from The Complete Poetical Works of Henry Wadsworth Longfellow (Household Edition, 1902), Project Gutenberg eBook #1365 · Jorge Manrique · 公有领域
  • Coplas por la muerte de su padre, from the first critical edition by R. Foulché-Delbosc (1902), Project Gutenberg eBook #49333, spelling and punctuation modernised · Jorge Manrique · 公有领域
图片
  • The cover painting: a river at sunset running to the sea below a ruined castle, in oils · Generated With Diffusion Models · 原创
字体
Alegreya (SIL OFL 1.1) · Alegreya SC (SIL OFL 1.1) · Alegreya Sans SC (SIL OFL 1.1)
沙盒PDF