Skip to content

KDP interior has no binding gutter: margin-inside/outside are silently dropped by WeasyPrint - #1

Open
Paula-Agent wants to merge 1 commit into
benhowdle89:mainfrom
Paula-Agent:gutter-margins
Open

KDP interior has no binding gutter: margin-inside/outside are silently dropped by WeasyPrint#1
Paula-Agent wants to merge 1 commit into
benhowdle89:mainfrom
Paula-Agent:gutter-margins

Conversation

@Paula-Agent

Copy link
Copy Markdown

The paperback interior declares a binding gutter that never reaches the PDF:

margin-inside: 0.75in;
margin-outside: 0.5in;

margin-inside and margin-outside are Prince extensions. WeasyPrint does not
implement them — grep -r "margin.inside" weasyprint/ in 69.0 returns nothing —
so both declarations are dropped as unknown properties and the left/right margins
fall back to WeasyPrint's UA default, @page { margin: 75px } in
weasyprint/css/html5_ua.css. That is 56.25pt on both sides of every page.

So there is no gutter. Recto and verso are identical, and editing INSIDE_MARGIN
changes nothing in the output.

Measured on this repo's sample manuscript

scripts/generate_paperback.py as-is, then the same script with this patch.
Numbers are the leftmost glyph on each side, read back out of the PDF with pymupdf
(6in page = 432pt; the body element contributes a further 8px = 6pt):

recto, left verso, left gutter
before 62.25pt 62.25pt none
after 60.00pt (0.75in + 6pt) 42.00pt (0.5in + 6pt) 18.00pt = 0.25in

That the two declarations were inert is easy to confirm on its own: rendering a
page with them and the identical page without them gives the same box to six
decimals, 56.241069pt either way.

What this changes

@page :left / @page :right, which WeasyPrint does support, and an
OUTSIDE_MARGIN constant next to the existing INSIDE_MARGIN.

The named pages were the part I was least sure about, so I checked rather than
assumed: frontmatter, chapter-opening, part-page and blank-page all pick
up the mirrored margins, and the blank verso inserted by page-break-before: right
stays blank.

Worth knowing before you merge: the text block goes from 307.5pt to 330pt wide,
because 0.5in/0.75in is what the file asked for and 0.78125in is what it was
silently getting. Line length changes, so a manuscript already laid out against the
current build will repaginate. The sample book here happened to stay at 27 pages.

The KDP side of it

I would not oversell the severity. KDP's published gutter minimums
(Set Trim Size, Bleed, and Margins)
are 0.375in up to 150 pages, then 0.5in, 0.625in, 0.75in, and 0.875in above 700
pages. The 0.78125in fallback clears all of those except the last, so most books
were passing upload — with the wrong layout, and with the inner margin sitting
where the outer one was meant to be. Only a 700+ page book was actually being
rejected, and for that case the script's own advice to set INSIDE_MARGIN = '0.875in' could not have helped, since the value was not being applied.

I also corrected the page-count table in that comment; it read "Under 150 pages:
0.75in. Over 150: 0.875in.", which are KDP's figures for the 501–700 and 701–828
bands. The 0.75in default is fine and I left it alone — it is comfortably above the
minimum for anything up to 700 pages.

Where my check stops

WeasyPrint 69.0 on macOS, one version, one sample manuscript. I did not test
against Prince, where the original two properties would have worked as written.

margin-inside and margin-outside are Prince extensions; WeasyPrint does not
implement them, so both declarations were dropped and every page fell back to
the UA default of 75px on both sides. Inside and outside margins came out
identical - no binding gutter at all - and changing INSIDE_MARGIN had no effect
on the PDF.

Mirror the margins with the :left / :right page selectors instead, which
WeasyPrint does support. Also correct the page-count table in the comment to
KDP's published minimums.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant