Proyectos

md2pdf

Rust Actualizado el 13 de agosto de 2026
portfolio

md2pdf — High-performance Markdown to PDF converter

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.

Features

  • 🚀 Converts giant .md files 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

Requirements

Installation

cd md2pdf
cargo build --release

The binary is placed at target/release/md2pdf.

Usage

Interactive TUI mode

cargo run --release -- --input ../mds --output ./output

Shows an interface with a file list, progress bar, ETA, and log.

No-TUI mode (single file)

cargo run --release -- --no-tui --input "file.md" --output ./output

No-TUI mode (entire directory)

cargo run --release -- --no-tui --input ../mds --output ./output

Using the binary directly

./target/release/md2pdf --no-tui --input file.md --output ./output

CLI Flags

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)

TUI Shortcuts

Key Action
q / Esc Quit
/ Navigate files
Enter / r Convert selected file
a Convert all files

Architecture

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).

Limitations

  • 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.

License

Apache 2.0