Skip to content

Latest commit

 

History

25 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

md2pdf

A command-line tool to convert Markdown files to PDF format, written in Rust.

Features

Currently Implemented ✅

  • Headings - H1 through H6 with automatic sizing
  • Text Formatting
    • Bold text
    • Italic text
    • Inline code with 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

Planned Features 🚧

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

Installation

From Source

# Clone the repository
git clone https://github.com/yourusername/md2pdf.git
cd md2pdf

# Build and install
cargo install --path .

Usage

# 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

Options

  • -o, --output <FILE> - Output PDF file path (defaults to input filename with .pdf extension)
  • -v, --verbose - Enable verbose output
  • -h, --help - Show help information

Examples

See the examples/ directory for sample markdown files:

# Try the full feature test
cargo run -- examples/full-test.md -o output.pdf --verbose

Architecture

md2pdf uses a clean pipeline architecture:

  1. Parser (pulldown-cmark) - Parses Markdown to event stream
  2. Document Builder - Converts events to Abstract Syntax Tree (AST)
  3. Layout Engine - Positions elements on pages with proper spacing
  4. 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).

Development

# Build
cargo build

# Run tests
cargo test

# Run with example
cargo run -- examples/sample.md -o test.pdf --verbose

Dependencies

  • pulldown-cmark - CommonMark markdown parser
  • printpdf - PDF generation
  • clap - CLI argument parsing
  • image - Image decoding (for future image support)

License

MIT

Status

This project is under active development. Core markdown features are implemented and working. Tables, images, and Mermaid diagrams are planned for future releases.

About

A command-line tool to convert Markdown files to PDF format, written in Rust

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages