April 4, 2026 · Updated November 22, 2026 · 6 min read
Markdown to PDF Without Losing Formatting: 7 Fixes
Why tables get cut off, code loses its colours and headings end up alone at the bottom of a page when you export Markdown to PDF, and how to fix each one.
Your Markdown looks right in the editor, then the PDF has a table running off the page, grey code with no colours, or a heading stranded at the bottom of a page. Most of these problems come from the source Markdown or the page setup, not from the converter itself. This guide goes through the common ones and how to fix them.
Just need the PDF?
If you only want to convert a file now, use the tinyMD Markdown to PDF converter. It runs in your browser, lets you set page size, orientation and margins, and keeps headings with the text that follows them. The rest of this guide explains what to do when a document still comes out wrong.
Try it yourself
Markdown to PDF Converter
Open a .md file, choose A4 or Letter, orientation and margins, and download. Free, nothing uploaded.
Open ToolWhy PDFs lose formatting
PDF has fixed pages; Markdown flows. A converter has to decide where each page ends, how wide a table may get and how code is styled. Without clear structure in the source it makes bad guesses.
- Tables wider than the page get squeezed or clipped
- Code blocks without a language name render as plain grey text
- Large images are scaled to the full page width
- A heading near the bottom of a page gets separated from its paragraph
The 7 fixes
- Wide tables: switch the page to landscape, or split the table into two narrower ones.
- Code without colours: name the language on the fence, for example ```python or ```js.
- Headings left alone at the bottom of a page: use a converter that keeps headings with the next block, or put a page break before the section.
- Chapters running together: add <!-- pagebreak --> between them, or start every H1 or H2 on a new page.
- Text too small or too large once printed: change the text size or the margins rather than editing font sizes in the Markdown.
- Broken table rows: give every row the same number of | cells as the header.
- Skipped heading levels: go H1, then H2, then H3 so the structure (and any table of contents) stays readable.
Check before you export
- Look at the live preview at the page size you will print
- Scroll to every table and code block
- Check that each heading is followed by its content
- Only then download the PDF
When to use Pandoc instead
Pandoc is the better choice for build pipelines, citations and bibliographies, or a custom LaTeX template. For a one-off PDF of a README, notes or a report, a browser converter is quicker because there is nothing to install.
FAQ
Why is my Markdown table cut off in the PDF?
It has more columns than fit across the page. Switch to landscape, use narrower margins, or split the table. Also check that every row has the same number of cells.
How do I keep syntax highlighting when converting Markdown to PDF?
Name the language after the opening fence (```python, ```js). Converters that highlight code, including tinyMD, need it to know which colours to use.
How do I add a page break in Markdown?
Markdown has no page break syntax of its own. Many converters, including tinyMD, accept <!-- pagebreak --> or \pagebreak on its own line. tinyMD can also start every H1 or H2 on a new page.