fix: PDF body fills page width (override pandoc CSS max-width)

Pandoc's --standalone HTML5 template applies max-width: 36em + margin: 0
auto + padding: 50px to body, centering content in a narrow column on
any page size. With wkhtmltopdf at 15mm page margins, effective content
margins were measuring ~55mm because pandoc's CSS added ~40mm of inner
padding on top.

Inject a header-includes <style> block that strips body's max-width,
margin, and padding so content fills the page minus wkhtmltopdf's own
page margins. Measured: 55mm → 15mm left margin.
This commit is contained in:
russell@unturf.com 2026-04-26 15:55:55 -04:00
parent d7fa7d1b93
commit 81344da09a
No known key found for this signature in database

View file

@ -220,6 +220,11 @@ def convert(source, from_format="markdown", to_format="html5", title=None, stand
# wkhtmltopdf defaults to ~25mm top which leaves a half-page of empty
# space above content. 12mm/15mm is enough to look printed without
# wasting paper.
#
# Pandoc's --standalone HTML5 template applies `max-width: 36em` and
# `padding: 50px` to body, centering content in a narrow column on
# any size paper. We want content to fill the page (minus wkhtmltopdf
# margins) so we override that CSS via header-includes.
if to_format == "pdf":
cmd.extend([
"--pdf-engine=wkhtmltopdf",
@ -227,6 +232,7 @@ def convert(source, from_format="markdown", to_format="html5", title=None, stand
"-V", "margin-bottom=12mm",
"-V", "margin-left=15mm",
"-V", "margin-right=15mm",
"-V", "header-includes=<style>html,body{max-width:none!important;padding:0!important;margin:0!important;}</style>",
])
if is_binary: