Crafting Publication-Grade Technical Documents with MD2PDF
How we engineered a browser-first Markdown to PDF engine using CSS Paged Media, KaTeX math typesetting, and zero-telemetry local rendering.
When writing documentation, engineering reports, or technical books, Markdown is unbeatable for speed. But turning that Markdown into an executive-ready PDF usually requires painful workflows: spinning up heavy headless Chrome instances, wrestling with LaTeX syntax, or paying SaaS subscriptions that harvest your document data.
I built MD2PDF (md2pdf.ladestack.in) to give engineers and technical writers an instant, local-first publishing studio. You type Markdown, see live typographical updates, and generate crisp, paginated PDF documents directly through your browser’s native print engine.
The Flaws of Cloud-Based PDF Generators
Most web-based PDF converters take your document, send it to a backend cluster running Puppeteer, and stream back a binary file. That architecture introduces three critical problems:
- Privacy leaks: Sensitive engineering blueprints, proprietary code, or financial reports leave your computer.
- High latency: Every preview iteration requires a complete network round-trip.
- Fragile page breaks: Headless browsers frequently split lines of code or headings across pages awkwardly.
With MD2PDF, document compilation never touches a remote server. The entire parser runs client-side using WebAssembly and standard web APIs.
Mastering CSS Paged Media
The secret to professional PDF output in modern browsers is the CSS Paged Media Module (@page). Instead of treating the document as an infinite scroll, we define physical paper geometry:
@page {
size: A4 portrait;
margin: 20mm 15mm 20mm 15mm;
@bottom-right {
content: counter(page);
font-family: monospace;
font-size: 9pt;
color: #71717a;
}
}
@page :first {
@bottom-right {
content: none;
}
}
h1, h2, h3 {
break-after: avoid;
page-break-after: avoid;
}
pre, table, blockquote {
break-inside: avoid;
page-break-inside: avoid;
}
By combining break-inside: avoid with targeted typography rules, code blocks and tables stay together on one page.
Native Mathematical Typesetting with KaTeX
Technical documents frequently demand formulas. Rather than rendering images of equations, MD2PDF integrates KaTeX directly into the Markdown parsing pipeline. Math formulas like inline geometry calculations or matrix transformations are converted into semantic SVG and HTML before printing, guaranteeing razor-sharp vectors at 1200 DPI.
The Local-First Guarantee
Whether you are preparing a software architecture document on a flight or documenting internal security protocols, MD2PDF works 100% offline. No analytics, no account requirements, and no document telemetry: just clean, beautiful documents on demand.