CLI tool with an interactive TUI for converting large Markdown files (20k+ lines) to PDF while preserving styles. Built in Rust with pulldown-cmark, printpdf, ratatui, and tokio.
- 🚀 Converts giant
.mdfiles without hanging (24k+ lines in ~0.2s) - ✍️ Preserves inline styles: bold, italics,
inline code - 📦 Code blocks with gray background, border, and line numbers
- 📊 Tables with borders, highlighted header, alternating rows, and auto-scaled columns
- 📝 Nested lists (ordered and unordered), blockquotes, horizontal rules
- 📄 Automatic and explicit page breaks with
[pagebreak] - 🖥️ Interactive TUI built with ratatui (progress bar, ETA, file selection)
- ⚙️ No-TUI mode for scripting and automation
- 🇪🇸 Full support for Spanish accents (WinAnsi/Latin-1)
- 📑 Code blocks and tables split across pages without losing content
- Rust toolchain (rustup + cargo). Install from https://rustup.rs
cd md2pdf
cargo build --releaseThe binary is placed at target/release/md2pdf.
cargo run --release -- --input ../mds --output ./outputShows an interface with a file list, progress bar, ETA, and log.
cargo run --release -- --no-tui --input "file.md" --output ./outputcargo run --release -- --no-tui --input ../mds --output ./output./target/release/md2pdf --no-tui --input file.md --output ./output| Flag | Description | Default |
|---|---|---|
--input <path> |
.md file or directory to convert |
./mds |
--output <dir> |
Directory where the PDFs are saved | ./output |
--no-tui |
Run without the graphical interface (stdout) | false (TUI enabled) |
| Key | Action |
|---|---|
q / Esc |
Quit |
↑ / ↓ |
Navigate files |
Enter / r |
Convert selected file |
a |
Convert all files |
md2pdf/
├── src/
│ ├── main.rs # Entry point, CLI, tokio runtime
│ ├── tui.rs # ratatui interface (progress, selection)
│ ├── converter.rs # Conversion orchestration (spawn_blocking)
│ ├── pdf_writer.rs # PDF engine (layout, fonts, pages)
│ ├── markdown.rs # Markdown parser → LayoutOps (pulldown-cmark)
│ └── progress.rs # Progress events (tokio channels)
Main crates: pulldown-cmark (parser), printpdf (PDF), ratatui + crossterm (TUI), tokio (async), textwrap (wrapping), clap (CLI).
- The built-in fonts (Helvetica, Courier) only support WinAnsi/Latin-1. Emoji and CJK characters are silently removed.
- Spanish accents (á, é, í, ó, ú, ñ, ¿, ¡) work correctly.
- Images embedded in the markdown are not rendered.
Apache 2.0