Markdown to PDF
Published Updated
Paste or upload Markdown, check the preview, and save it as a PDF from your browser's print dialog.
The browser makes the PDF
This page converts your Markdown to HTML with the marked library, places it in a fixed stylesheet inside a hidden frame, and calls the browser's print function. You finish by choosing Save as PDF as the printer, so the file is produced by your own browser's PDF writer. That is also why the text in the PDF stays selectable.
marked aims to follow CommonMark and the GitHub Flavored Markdown additions, so tables, task lists, strikethrough and autolinks are supported. The frame is sandboxed without script permission, so script tags in the text do not run.
What renders, tested with marked 18
We ran the library version this site uses on small samples.
| You write | In the PDF |
|---|---|
| Pipe tables, task lists, ~~strikethrough~~ | Rendered, with disabled checkboxes for tasks |
| Fenced code, with a language name | Gray monospace box, no syntax colors |
| https://example.com on its own | Becomes a link |
| YAML front matter | A rule, then the lines as text (plain key: value lines become one heading) |
| Footnote [^1] | Left as typed, with the note as a paragraph (a one-word note makes a link) |
| Math between dollar signs, :emoji: codes | Left as typed |
| Raw HTML such as a div | Passed through |
Converting Markdown to PDF
Step 1
Upload or paste Markdown
Add a .md or .txt file, or type into the box. The text opens in an Edit tab.
Step 2
Check the Preview tab
The preview uses the same stylesheet as the PDF. Page breaks appear only when printing, and paper size and margins come from the print dialog.
Step 3
Convert and save as PDF
Press Convert MD to PDF, then choose Save as PDF in the print dialog that opens.
Prepare the file first
A few edits before you press the button save a second try:
- Delete front matter.
- Wrap code lines at roughly 70 characters.
- Swap relative image paths for full https:// addresses.
- Turn footnotes into plain notes or parentheses.
For the opposite direction, see PDF to Markdown, and for Word files Markdown to Word.
How long the PDF gets
We ran the site's marked 18.0.7 and the tool's own print stylesheet (copied from its component) on generated Markdown, and printed the result with page.pdf in Chromium 153.0.8010.12, the build that ships with Playwright, headless. That is Chromium's built-in PDF printing, not the print dialog: we chose Letter paper and 0.5 inch margins ourselves, and your dialog settings will differ. The text is one heading followed by identical-length paragraphs of plain prose.
| Markdown input | Pages | PDF size | Print time |
|---|---|---|---|
| 262 words (1,529 characters) | 1 | 40,450 B | 19 ms |
| 1,562 words (9,179 characters) | 5 | 47,381 B | 19 ms |
| 7,802 words (46,100 characters) | 22 | 78,782 B | 29 ms |
| 39,002 words (231,401 characters) | 108 | 238,218 B | 119 ms |
Once the text ran past one page that came to about 310 to 360 words per page at the stylesheet's 16-pixel text and 1.6 line spacing. Real documents with headings, lists and code will give other counts.
Page breaks, tables and long code lines
- Headings: in a document of 80 sections with a heading and two paragraphs each, 0 of the 20 pages ended on a heading. The stylesheet asks for no break after h1 to h3, and in this test the browser followed it.
- A 12-column table with short cells fit on one page. Its text reached 580 points on a 612-point page whose right margin begins at 576, so it ran 4 points past the margin line but stayed on the page.
- Code blocks do not wrap. In a layout 720 pixels wide, which is Letter paper minus our margins, the code box was 656 pixels wide and held 72 characters of a line. A 60-character and a 72-character line fit. A 90-character line overflowed by 150 pixels, a 131-character one by 506 and a 200-character one by 1,104. Overflow in the box is set to auto, which cannot scroll on paper.
- Images: a picture given as a data: address loaded. A picture given as a file name next to the .md did not (a broken image, width 0).
What is inside the PDF
Reading a small test PDF back with pdf.js 5.4.624 found the headings, sentences and table cells as text items, in small pieces, and the link as a link annotation pointing at https://example.com/. So the text is real text, not a picture of it, and the link is a link annotation.
The tool puts your Markdown in a frame with sandbox set to allow-same-origin and allow-modals, and no allow-scripts. We loaded a page with a script and an inline event handler into a frame with those settings in Chromium 153, Firefox 155.0 and Playwright's WebKit build (user agent Version/26.6, not the Safari app). Neither ran in any of them.
Markdown to PDF questions
Can I change the font, margins or paper size?
The look is fixed: a system sans-serif body at 800 px maximum width, grey code blocks and bordered tables. Paper size, margins and whether headers and footers print are set in the browser's print dialog, not on this page.
Why does my front matter show up as a heading?
YAML front matter is not recognized. The opening --- becomes a horizontal rule and the lines after it print as text. A block of plain key: value lines before the second --- becomes one heading, but a list or a blank line inside the block splits it up. Delete the block before converting.
Why are my images missing?
Relative paths such as pic.png point to files next to your .md, which the page cannot read. Use full https:// addresses or data: URLs for images that need to appear in the PDF.
Do footnotes, math or emoji codes work?
No. A footnote marker like [^1] stays as typed and its note prints as an ordinary paragraph, unless the note is one word or a web address, which turns the marker into a link. $E=mc^2$ stays as typed, and :smile: is not converted. Tables, task lists, strikethrough and fenced code blocks do work.
Why are my long code lines cut off?
Code blocks are not wrapped when printed. In a layout 720 pixels wide (Letter paper with 0.5 inch margins) in Chromium 153, a 72-character line fit in the code box and a 131-character line ran 506 pixels past it. Break long lines in the Markdown before converting.
Why does my PDF have a date and a web address in the margins?
Some browsers print a header and footer by default. This page adds neither, so switch them off in the print dialog under its extra settings.
How many pages will my document be?
With Letter paper and 0.5 inch margins in Chromium 153, 1,562 words of plain paragraphs made 5 pages and 7,802 words made 22. Headings, code and tables will change that, and your print dialog sets its own paper and margins.
Is the text in the PDF selectable and are the links clickable?
In our test, yes. pdf.js read the text as text, in small pieces, and found a link annotation for a Markdown link.
Can a script in my Markdown run?
Not in the frame the tool uses. A script and an inline event handler did not run in a frame with the same sandbox setting, in Chromium 153, Firefox 155 and the WebKit build.