DEV Community

eth shihao
eth shihao

Posted on

KDP paperback spine width and PDF BleedBox math in TypeScript

Add 24 pages to a 240-page, 6 × 9 in paperback on cream paper and the spine grows from 0.600 to 0.660 in. The back fold stays 6.125 in from the left edge of the PDF. The front fold moves from 6.725 to 6.785 in. An export that scales the whole cover to the new width moves elements on both panels, including anything aligned to the folds.

Calculate the full wrap in one coordinate system

For a left-to-right paperback, the horizontal order is outer bleed, back, spine, front, outer bleed. KDP specifies 0.125 in of outer bleed and publishes separate per-page factors for each paper and ink combination. Use the page count KDP derives from the final interior and cross-check the result against the template for that trim and stock. KDP paperback cover requirements · KDP cover calculator and templates

Dimension Formula 264-page cream example
Spine width Pages × paper factor 0.660 in
Wrap width 2 × trim width + spine + 2 × bleed 12.910 in
Wrap height Trim height + 2 × bleed 9.250 in
Back fold x Bleed + trim width 6.125 in
Front fold x Back fold x + spine width 6.785 in

The proof uses a PDF page unit of 1/72 in. Its MediaBox and CropBox span the exported page, and its BleedBox covers that same area because the file has no extra printer margin. Its TrimBox describes the outer cut around the full wrap. The two folds are positions inside that rectangle. The proof draws them as strokes so you can compare revisions visually. PDF 1.7, section 14.11.2 · pdf-lib PDFPage API

Save this as spine-proof.mts. With Node.js 24, run npm install pdf-lib@1.17.1 and then node spine-proof.mts.

import assert from "node:assert/strict";
import { writeFile } from "node:fs/promises";
import { PDFDocument, rgb } from "pdf-lib";

const inchesPerPage = {
  blackWhite: 0.002252,
  blackCream: 0.0025,
  standardColor: 0.002252,
  premiumColor: 0.002347,
};
type Stock = keyof typeof inchesPerPage;
const pt = (inches: number) => inches * 72;

function wrap(pages: number, stock: Stock, trimWidthIn: number, trimHeightIn: number) {
  if (!Number.isSafeInteger(pages) || pages <= 0 || pages % 2 !== 0) {
    throw new Error("Use the final, positive even page count");
  }
  if (![trimWidthIn, trimHeightIn].every((size) => Number.isFinite(size) && size > 0)) {
    throw new Error("Trim dimensions must be positive inches");
  }

  const bleed = pt(0.125);
  const spine = pt(pages * inchesPerPage[stock]);
  const trimWidth = pt(trimWidthIn);
  const trimHeight = pt(trimHeightIn);
  return {
    bleed,
    spine,
    trimWidth,
    trimHeight,
    width: 2 * trimWidth + spine + 2 * bleed,
    height: trimHeight + 2 * bleed,
    backFold: bleed + trimWidth,
    frontFold: bleed + trimWidth + spine,
  };
}

const before = wrap(240, "blackCream", 6, 9);
const after = wrap(264, "blackCream", 6, 9);
assert.equal(before.backFold, after.backFold);
assert.equal((after.frontFold - before.frontFold).toFixed(2), "4.32");
assert.equal(after.width.toFixed(2), "929.52");

const { bleed, width, height, frontFold, backFold } = after;
const doc = await PDFDocument.create();
const page = doc.addPage([width, height]);
page.setCropBox(0, 0, width, height);
page.setBleedBox(0, 0, width, height);
page.setTrimBox(bleed, bleed, width - 2 * bleed, height - 2 * bleed);

page.drawRectangle({ x: 0, y: 0, width, height, color: rgb(0.94, 0.96, 0.98) });
page.drawRectangle({
  x: bleed, y: bleed, width: width - 2 * bleed, height: height - 2 * bleed,
  borderWidth: 0.5, borderColor: rgb(0.25, 0.25, 0.25),
});

for (const [x, color] of [
  [backFold, rgb(0.05, 0.30, 0.65)],
  [frontFold, rgb(0.05, 0.30, 0.65)],
  [before.frontFold, rgb(0.80, 0.25, 0.15)],
] as const) {
  page.drawLine({
    start: { x, y: bleed }, end: { x, y: height - bleed },
    thickness: 0.8, color,
  });
}

page.drawText("GEOMETRY PROOF - blue: new folds; red: old front fold", {
  x: bleed + 18, y: height - bleed - 26, size: 12,
});
const bytes = await doc.save();

const [checked] = (await PDFDocument.load(bytes)).getPages();
assert.deepEqual(checked.getMediaBox(), checked.getBleedBox());
const trim = checked.getTrimBox();
assert.deepEqual([trim.x, trim.y, trim.width.toFixed(2), trim.height], [9, 9, "911.52", 648]);

await writeFile("cover-geometry-proof.pdf", bytes);
console.log(`Full wrap: ${width.toFixed(2)} x ${height.toFixed(2)} pt`);
console.log(`Folds: ${backFold.toFixed(2)} and ${frontFold.toFixed(2)} pt`);
Enter fullscreen mode Exit fullscreen mode

The file measures 929.52 × 666.00 pt, with folds at 441.00 and 488.52 pt. The old and new front folds are 4.32 pt apart. Inspect the exported boxes with pdfinfo -box cover-geometry-proof.pdf if Poppler is installed. A box records a boundary. Artwork still has to extend to that boundary wherever ink should reach the cut.

Apply the change to the cover artwork

In the source layout, keep the back panel fixed, move the front panel 4.32 pt to the right, and rebuild or extend the strip between the folds. Check any artwork that crosses the spine at full size. Export the final artwork alone, leaving the proof guides and label out of the upload. Check barcode clearance and review the uploaded cover in KDP Print Previewer. KDP paperback cover checklist

SpineRetrofit is published by the team behind this article. Its browser preview compares the old and new folds for a single-page, unrotated cover. Its repair workflow is designed for black ink on white or cream paper with the same trim and stock and a solid-color spine. SpineRetrofit

AI disclosure. This article was generated with AI.

Top comments (0)