Markdown to PDF Converter
Convert Markdown files to professionally formatted PDF documents. Paste or upload .md files and download clean, styled PDFs instantly in your browser.
About
Markdown is a lightweight markup language with roughly 30 formatting primitives. Converting it to PDF requires a full text layout engine: glyph-width computation, word-wrap against a fixed page width of 595.28 pt (A4), line-height stacking, and page-break insertion when y exceeds the bottom margin. A naive conversion that ignores font metrics produces lines that overflow or orphan headings at page bottoms. This tool parses Markdown into a block-level AST, resolves inline formatting (bold, italic, code, links), then runs a layout pass using Helvetica width tables (CP1252 encoding, 315 glyph entries) to compute precise line breaks. The output is a valid PDF 1.4 binary with proper cross-reference tables - not an image-wrapped hack. Limitation: embedded images render as linked text references since Base64 bitmap embedding without a library would exceed practical single-page scope. Tables, nested lists, and fenced code blocks are fully supported.
Formulas
The PDF layout engine computes line breaks using per-glyph width accumulation against the available text area width. The usable width W on an A4 page is:
For each word, the engine computes its rendered width:
where gi is the glyph width of character i from the Helvetica metrics table (Adobe standard, values in 1/1000 of a unit). When the accumulated line width x + wword > W, a line break is inserted. The vertical cursor y decrements by the line height L = fontSize × 1.4. A page break triggers when y < Mbottom (72 pt).
The PDF cross-reference table offset for object k is computed as the cumulative byte length of all preceding objects:
where len returns the byte length of the serialized PDF object including line terminators. This ensures the PDF reader can random-access any object for rendering.
Reference Data
| Markdown Element | Syntax | PDF Rendering | Font | Size (pt) |
|---|---|---|---|---|
| Heading 1 | # Text | Bold, large, top margin | Helvetica-Bold | 22 |
| Heading 2 | ## Text | Bold, medium | Helvetica-Bold | 18 |
| Heading 3 | ### Text | Bold, small | Helvetica-Bold | 15 |
| Heading 4 | #### Text | Bold, body-size | Helvetica-Bold | 13 |
| Heading 5 | ##### Text | Bold, small | Helvetica-Bold | 11 |
| Heading 6 | ###### Text | Bold, smallest | Helvetica-Bold | 10 |
| Paragraph | Plain text | Regular body text | Helvetica | 11 |
| Bold | **text** | Bold inline span | Helvetica-Bold | Inherited |
| Italic | *text* | Oblique inline span | Helvetica-Oblique | Inherited |
| Bold Italic | ***text*** | Bold-Oblique span | Helvetica-BoldOblique | Inherited |
| Inline Code | `code` | Monospace, gray bg | Courier | Inherited |
| Code Block | ```lang | Monospace block, shaded | Courier | 9 |
| Unordered List | - item | Bullet • indented | Helvetica | 11 |
| Ordered List | 1. item | Number. indented | Helvetica | 11 |
| Blockquote | > text | Indented, gray bar | Helvetica-Oblique | 11 |
| Horizontal Rule | --- | Gray line across page | - | - |
| Link | [text](url) | Blue underlined text | Helvetica | 11 |
| Image |  | Alt text as caption | Helvetica-Oblique | 10 |
| Table | GFM pipe syntax | Bordered grid layout | Helvetica | 10 |
| Strikethrough | ~~text~~ | Rendered as regular text (noted) | Helvetica | 11 |
| Task List | - [x] done | Checkbox symbol + text | Helvetica | 11 |