How a Word file becomes a printed book: line breaks, widows and the KDP gutter

September 25, 2026 · 8 min read · by Nobody

A Word document has no pages, not really. It has paragraphs, and Word decides where the pages fall while you type. A printed book is the opposite: every page is fixed, the left and right pages mirror each other, and the printer wants a PDF where nothing moves. Somebody has to decide where every line and every page ends.

I built Bookcut to make that decision for self-published authors. You drop in the .docx, it finds the chapters, and it sets the book for an Amazon KDP paperback and an EPUB. All the typesetting runs in your browser tab. This post walks through the three problems that took the most thought, with numbers from the first three chapters of Pride and Prejudice, which is the sample text on the site.

1. Breaking lines

Book text is justified: every full line ends exactly at the right edge, so the spaces between words have to stretch or shrink. My engine gives a word space a natural width of 0.25 em, lets it shrink to 0.2 em and stretch to 0.45 em. Past 0.45 em a line looks loose, with visible holes between words, and the engine reports it.

The obvious way to break lines is greedy: put as many words on the line as fit, then start the next one. It's fast and it never looks back, which is its problem. A good line early in the paragraph can force a terrible line three lines later.

The better way comes from Donald Knuth and Michael Plass, who worked it out for TeX. Look at every possible way to break the whole paragraph, give each line a cost that grows sharply with how far its spaces stretch or shrink, and pick the set of breaks with the lowest total. It sounds expensive, but the best way to end a line after a given word doesn't depend on what comes later, so it's a shortest-path search over break points. My version is a simplified one: it adds a cost for each hyphenated line, and a very large one for two hyphenated lines in a row.

I expected this to fix everything. So I measured it. I set every paragraph of the three chapters in the Classic design (EB Garamond at 11.5 pt), once with a greedy breaker and once with the total-fit breaker, and counted the lines whose spaces had to stretch past 0.45 em.

5 x 8 in, no hyphenation (about 274 justified lines)greedy47total fit485 x 8 in, hyphenation ongreedy18total fit116 x 9 in, no hyphenation (about 208 justified lines)greedy20total fit126 x 9 in, hyphenation ongreedy6total fit5
Lines with word spaces wider than 0.45 em, Pride and Prejudice chapters 1 to 3, Classic design. Fewer is better.

Two things surprised me.

On a narrow 5 x 8 page without hyphenation, the algorithm made no difference at all: 47 loose lines against 48. A line of that width holds about eight or nine words of Austen, and when the next word is "neighbourhood" there is simply no good place to break. Total fit can spread the pain around the paragraph, but it can't make a long word shorter.

Hyphenation did most of the work. Turning it on at 5 x 8 cut the loose lines from 48 to 11, and on top of that total fit beat greedy by 18 to 11. At 6 x 9 the wider line gives both methods more room, and the gap is small once hyphenation is on. So Bookcut hyphenates by default, with rules taken from how book typesetters usually do it: only words of 6 letters or more, at least 3 letters before the hyphen and 2 after, and never on the last word of a paragraph.

2. Widows and orphans

Once the lines exist, they have to be poured into pages. The rule every book designer knows: a paragraph should never leave its first line alone at the bottom of a page (an orphan), or its last line alone at the top of the next one (a widow). A heading also shouldn't sit at the bottom of a page with its text on the next.

Page filled to the bottomwidowPage ended one line earlyEach short rule is one line of text. The accented lines are the end of one paragraph.
Moving one line to the next page leaves a short gap at the foot of the left page, which readers don't notice. A stranded line at the top of a page, they do.

My page breaker handles this with a flag on every line: "ending the page after me would strand a line". It fills a page as far as it can, and if the last line it placed carries that flag, it walks back until it finds a line where a break is safe. The walk back is limited to 6 lines. Past that the page would look visibly short, so the engine fills the page anyway and lists the widow in the preview, where the author can decide. Headings are flagged the same way and stay with at least two lines of their text. A scene break never ends a page either, because at the foot of a page a reader can't tell it's there.

Pages then get their furniture: running heads (the author on left pages, the title on right pages), page numbers, and none of either on chapter openers or blank pages.

3. The gutter depends on the page count

This is the part that surprised me most. A thick paperback curves into its spine, so the inside margin (the gutter) has to be wider the more pages the book has, or the text disappears into the fold. KDP publishes the minimum on its help page for trim size, bleed and margins:

Minimum inside margin (inches), by page count24 to 1500.375151 to 3000.5301 to 5000.625501 to 7000.75701 to 8280.875
From KDP's paperback formatting help. Outside, top and bottom margins must be at least 0.25 in when the book has no bleed.

Now the loop: the margins decide how wide the lines are, the line width decides how many lines there are, and the number of lines decides the page count, which decides the margins. A book that sets at 300 pages with a 0.5 in gutter might need 0.625 in, and with the narrower lines it now sets at 304 pages. That's fine, 304 is still in the same band. But it has to be checked.

Bookcut estimates the page count from the word count first, lays the book out with the margins for that estimate, and then looks at the real page count. If it landed in a different band, it lays the whole book out again with the new margins. Margins only ever get wider after the first correction, so the passes can't bounce between two bands forever, and there is a hard limit of 6 passes. Each design also has its own preferred margins, often wider than KDP's minimum for a short book, and the band only takes over once it asks for more than the design does. One of the tests sets a generated 99,000 word novel at 5 x 8 in, which comes out over 700 pages and ends with the 0.875 in gutter KDP asks for.

A few more rules come after that. The page count must be even and at least 24, so the engine adds blank pages at the end. Recto (right-hand) pages have the gutter on the left and verso pages on the right. Every page is exactly the trim size with no bleed and no crop marks. The fonts (four open-licensed book faces) are embedded in the PDF.

What the author sees

The preview in the browser draws each page as SVG from the same layout the PDF is written from, word by word at the same positions, so the pages you read are the pages KDP prints. Next to it is a check panel with the final page count, the gutter KDP asks for at that length and the one the book actually has, the smallest text size and the blank pages.

If you have a manuscript waiting, try Bookcut. Importing, fixing the outline and previewing every page are free. The print PDF and the EPUB are $12 for the book, once, and you can export again free for 30 days when you find a typo.