KDP interior has no binding gutter: margin-inside/outside are silently dropped by WeasyPrint - #1
Open
Paula-Agent wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The paperback interior declares a binding gutter that never reaches the PDF:
margin-insideandmargin-outsideare Prince extensions. WeasyPrint does notimplement 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 }inweasyprint/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_MARGINchanges nothing in the output.
Measured on this repo's sample manuscript
scripts/generate_paperback.pyas-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
bodyelement contributes a further 8px = 6pt):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.241069pteither way.What this changes
@page :left/@page :right, which WeasyPrint does support, and anOUTSIDE_MARGINconstant next to the existingINSIDE_MARGIN.The named pages were the part I was least sure about, so I checked rather than
assumed:
frontmatter,chapter-opening,part-pageandblank-pageall pickup the mirrored margins, and the blank verso inserted by
page-break-before: rightstays 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.