A command-line tool to convert Markdown files to PDF format, written in Rust.
- Headings - H1 through H6 with automatic sizing
- Text Formatting
- Bold text
- Italic text
Inline codewith monospace font- Mixed styling (bold + italic, etc.)
- Lists
- Unordered lists with bullet points
- Ordered lists with numbering
- Nested lists with proper indentation
- Code Blocks - Fenced and indented, with monospace font
- Blockquotes - Indented visual styling
- Horizontal Rules - Visual separators
- Pagination - Automatic page breaks
- Tables with column alignment
- Images (PNG, JPEG)
- Mermaid diagrams (optional, requires mermaid-cli)
- Improved text wrapping and line breaking
- Customizable themes and styling
- Links (clickable or footnotes)
# Clone the repository
git clone https://github.com/yourusername/md2pdf.git
cd md2pdf
# Build and install
cargo install --path .# Convert a markdown file to PDF
md2pdf input.md -o output.pdf
# Output defaults to same name with .pdf extension
md2pdf document.md
# Verbose mode to see progress
md2pdf document.md --verbose-o, --output <FILE>- Output PDF file path (defaults to input filename with .pdf extension)-v, --verbose- Enable verbose output-h, --help- Show help information
See the examples/ directory for sample markdown files:
# Try the full feature test
cargo run -- examples/full-test.md -o output.pdf --verbosemd2pdf uses a clean pipeline architecture:
- Parser (
pulldown-cmark) - Parses Markdown to event stream - Document Builder - Converts events to Abstract Syntax Tree (AST)
- Layout Engine - Positions elements on pages with proper spacing
- Renderer (
printpdf) - Generates final PDF output
Most of the core logic (layout engine, document model) is custom-built, while we leverage battle-tested libraries for infrastructure (PDF generation, markdown parsing).
# Build
cargo build
# Run tests
cargo test
# Run with example
cargo run -- examples/sample.md -o test.pdf --verbosepulldown-cmark- CommonMark markdown parserprintpdf- PDF generationclap- CLI argument parsingimage- Image decoding (for future image support)
MIT
This project is under active development. Core markdown features are implemented and working. Tables, images, and Mermaid diagrams are planned for future releases.