Markdown to PDF, typeset properly

Markdown was designed to be readable as plain text. A PDF is meant to arrive exactly as it was set. Most converters lose the second promise on the way: they render your Markdown as a webpage, then print the webpage. This page explains why that output looks the way it does, and what typeset output looks like instead.

Why most Markdown-to-PDF output looks wrong

The overwhelming majority of converters (the online tools, the editor export buttons, the npm packages) share one architecture: render HTML, print it. Browsers are superb at scrolling and terrible at pages, so the symptoms are always the same:

None of this is a bug in any one tool. It is what printing a webpage is.

What typeset output looks like

A typesetting engine works the opposite way: it considers the paragraph as a whole and chooses the set of line breaks that reads best, the way books have been set for centuries. Concretely, in legivel's output:

Sample: report PDF Sample: math PDF Sample: diagrams PDF

Your options today

RouteGood forThe trade
Online converter toolsOne file, right now, freeBrowser-print output; your document uploaded to someone's server
Editor exportNotes, draftsSame browser-print engine underneath
Command-line typesetting toolchainsReal typographic qualityA multi-gigabyte toolchain to install, version, and maintain
Browser-automation APIsHTML you already haveA headless browser per request: slow, heavy, and still webpage pagination
legivelTypeset quality at API speed and volumeIn private beta: request access below

Convert Markdown to PDF from your code

curl -X POST https://api.legivel.com/v1/render \
  -H "content-type: text/markdown" \
  --data-binary @report.md \
  -o report.pdf

Per-document options (themes, feature toggles, light or dark) travel as JSON:

curl -X POST https://api.legivel.com/v1/render \
  -H "content-type: application/json" \
  -d '{"markdown": "# Quarterly report\n…", "features": {"theme": "dark"}}' \
  -o report.pdf

For AI workflows there is a native MCP server: your agents write Markdown, legivel makes it a finished document.

Frequently asked

What is the easiest way to convert Markdown to PDF?

For a single file, any online converter will do, and the result will look like a printed webpage. If the document matters (it goes to a client, a regulator, a customer), the easiest way that also looks right is an API call to a typesetting engine.

Is a free command-line toolchain the best converter?

A command-line typesetting toolchain produces genuinely typeset output, and it is free. The cost is the toolchain: a multi-gigabyte install, template debugging, and version drift across machines and CI. legivel exists to give that class of output as a single HTTP call.

Why does my Markdown PDF look bad?

Almost always because it was printed from a browser: greedy line wrapping, no hyphenation, CSS pagination. See the symptom list above.

Can I control page breaks?

You should not have to. The engine keeps headings with their text, repeats table headers, and avoids widows and orphans by construction.

Do tables and code blocks survive?

Tables keep alignment and repeat headers across pages. Code keeps its highlighting and wraps instead of overflowing.

Does Mermaid work? Does math work?

Thirty-two Mermaid diagram kinds and TeX math, all as vectors. Large diagrams get their own correctly sized page.

What about my images?

Images embedded in the document always render. Images linked from the web load too, for signed-in accounts, over a secure connection, and are never stored. Your document and the PDF leave our server the moment the PDF is delivered.

Can I convert Markdown to PDF by API?

Yes, that is what legivel is: REST for every document, MCP for AI agents.

legivel is in private beta.
Be first in line: tell us what you would generate.

Request beta access