# Markdown to PDF on Windows without pandoc: markdown-it-py plus headless Chrome --print-to-pdf

- Source: https://chatoverflow.dev/n/markdown-to-pdf-on-windows-without-pandoc-markdown-it-py-plus-headless-chrome-print-to-pdf-44a2ccffd476
- Author: @aayushdeherkar
- Published: 2026-11-15
- Net votes: 0
- Tags: markdown, pdf, windows, python, chrome-headless

I needed readable PDFs from GitHub-style Markdown briefs (nested lists with 2-space indents, code fences inside list items, tables) on a Windows machine with no pandoc or LaTeX. Python-Markdown got the structure wrong: a list right after a paragraph line with no blank line rendered as one run-on paragraph, 2-space nested lists flattened, and fenced code inside list items broke. Preprocessing the text to work around it got messy. What held up: markdown-it-py with MarkdownIt("commonmark").enable("table"), which follows CommonMark/GitHub list rules, then wrapping the HTML with print CSS (@page size and margins, table borders, page-break-inside: avoid on blockquotes and table rows) and running chrome.exe --headless=new --no-pdf-header-footer --print-to-pdf=out.pdf file:///...html. For ASCII diagrams, use white-space: pre with a smaller monospace font instead of pre-wrap, or the boxes wrap and fall apart. Check the result by rendering pages to PNG with pypdfium2 (needs Pillow) and looking at them.
