Skip to the content
MdReader

Markdown to PDF

Render the document first, read it, then print it to PDF from the browser. There is no conversion service in between.

Preview

Incident review: cache stampede, 14 September

What happened

At 09:12 the cache entry for the pricing table expired. Every request that arrived in the next four seconds missed the cache and went to the database, which reached its connection limit at 09:12:06. Recovery took eleven minutes.

Timeline

Time Event
09:12 Pricing cache entry expires
09:13 Database connection pool exhausted
09:17 Rate limit applied at the edge
09:23 Cache warm, error rate back to normal

Fix

// One caller refreshes; the rest wait for it rather than piling on.
await _refreshLock.WaitAsync(cancellationToken);

Follow-up

  • Single-flight refresh shipped
  • Alert on connection-pool saturation

How it works

Two steps, and the second one is your browser's.

  1. The Markdown is rendered to a page, the same way every other page on this site is.
  2. Save as PDF opens the browser's print dialog with only that page on the sheet. Pick "Save as PDF" as the destination and choose where it goes.

There is no conversion service and no queue. Your text reaches MdReader's server, which renders it and sends HTML back; the PDF itself is written by your browser, on your machine. Nothing about the document is stored on the way.

What survives

Syntax colours. Code keeps its highlighting. The grey block behind it only prints if you switch on the "Background graphics" option, which browsers keep off by default.

Diagrams. A Mermaid diagram is an SVG, so it prints as a drawing rather than a picture of one. Zoom into the PDF and the lines stay sharp. The button redraws them in the light palette first, so a dark-themed screen still gives a readable page.

Math. KaTeX writes HTML, not images, so the notation stays selectable text in the PDF.

Page breaks in sensible places. Code blocks, tables and alert boxes are asked not to split across two sheets, which browsers honour whenever the block fits on one.

What you cannot control

Page size, orientation and margins are whatever you choose in the print dialog. MdReader sets none of them, which means your browser's defaults apply and there is no setting here to override them.

There is no way to force a page break. Markdown has no syntax for one, and the HTML that could carry one is removed by the sanitizer along with everything else that can carry a style attribute. Long documents break where they break. Splitting the file at a heading and printing the parts separately is the only reliable way to control it.

Doing it from the desktop app

The Windows app has two ways out. Ctrl+P opens the same print dialog as here, and Ctrl+Shift+S ("Export as PDF") skips it: pick a file name and the PDF is written straight out, with the code-block backgrounds already switched on. The app does that when the file is on your disk and you would rather not paste it anywhere.

Questions

Is my document uploaded to a conversion service?

No. The text goes to MdReader's own server, which renders it to HTML and sends it back. The PDF is written by your browser on your own machine.

Does the PDF keep syntax highlighting and diagrams?

Code keeps its syntax colours, Mermaid diagrams print as vector drawings rather than pictures, and KaTeX math prints as selectable text. Block backgrounds only appear if you switch on your browser's background graphics option.

Which page size and margins does it use?

Whichever ones you choose in the print dialog. MdReader sets no page size and no margins of its own, so the defaults are your browser's.

How do I force a page break?

You cannot, and that is a real limitation. Markdown has no page-break syntax, and the HTML that could carry one is removed by the sanitizer. Printing does keep code blocks, tables and alerts from being split across two pages.