A fast and elegant Markdown to PDF converter built with Rust, featuring syntax highlighting and beautiful typography.
- 🎨 Beautiful Typography - Professional document styling with Crimson Text and Inter fonts
- 🌈 Syntax Highlighting - Code blocks with syntax highlighting using Syntect
- 📱 Responsive Design - Optimized for both screen and print
- ⚡ Fast Conversion - Built with Rust for maximum performance
- 🎯 Easy CLI - Simple command-line interface
- 📄 Rich Markdown Support - Tables, lists, blockquotes, images, and more
- Rust: Install from https://rustup.rs/
- Chrome/Chromium: Required for PDF generation
- Ubuntu/Debian:
sudo apt install chromium-browser
- Fedora:
sudo dnf install chromium
- Arch:
sudo pacman -S chromium
- macOS: Install Chrome from official website
- Windows: Install Chrome from official website
- Ubuntu/Debian:
- Clone the repository:
git clone <repository-url>
cd md2pdf
- Build the project:
./build.sh
Or manually:
cargo build --release
- The executable will be created at
target/release/md2pdf
Copy the executable to a directory in your PATH:
sudo cp target/release/md2pdf /usr/local/bin/
# Convert markdown file to PDF
md2pdf -i document.md
# Specify output file
md2pdf -i document.md -o output.pdf
# Custom page margins (in pixels)
md2pdf -i document.md -m 75
USAGE:
md2pdf [OPTIONS] --input <INPUT>
OPTIONS:
-i, --input <INPUT> Input Markdown file
-o, --output <OUTPUT> Output PDF file (default: same name as input with .pdf)
-m, --margin <MARGIN> Page margin in pixels (default: 50)
-h, --help Print help information
-V, --version Print version information
# Convert README.md to README.pdf
md2pdf -i README.md
# Convert with custom output name
md2pdf -i documentation.md -o manual.pdf
# Convert with larger margins
md2pdf -i article.md -m 100
# Convert guide with custom name and margins
md2pdf -i guide.md -o user-guide.pdf -m 75
- Headers (H1-H6) with elegant typography
- Text formatting (bold, italic, strikethrough)
- Code blocks with syntax highlighting
- Inline code with distinct styling
- Lists (ordered and unordered)
- Tables with alternating row colors
- Blockquotes with left border styling
- Links with hover effects
- Images with rounded corners and shadows
- Horizontal rules
- Task lists
- Footnotes
The converter uses a built-in CSS template optimized for PDF generation. The styling includes:
- Fonts: Crimson Text (serif) for body text, Inter (sans-serif) for headings
- Colors: Professional color scheme with good contrast
- Layout: Responsive design with proper spacing
- Code: Dark theme syntax highlighting
- Print: Optimized styles for PDF output
pulldown-cmark
- Markdown parsingsyntect
- Syntax highlightingheadless_chrome
- PDF generationtokio
- Async runtimeclap
- Command line argument parsinganyhow
- Error handling
md2pdf/
├── src/
│ └── main.rs # Main application code
├── md/ # Example markdown files
├── Cargo.toml # Rust dependencies
├── build.sh # Build script
└── README.md # This file
cargo build
cargo test
cargo build --release
The converter generates professional-looking PDFs with:
- Clean, readable typography
- Proper spacing and margins
- Syntax-highlighted code blocks
- Responsive tables
- Styled blockquotes and lists
If you get an error about Chrome/Chromium not being found:
- Install Chrome or Chromium using your system's package manager
- Make sure it's accessible in your PATH
- On some systems, you may need to install additional dependencies
If you encounter permission errors:
chmod +x target/release/md2pdf
For very large markdown files, you may need to increase the timeout or process them in smaller chunks.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Initial release
- Basic Markdown to PDF conversion
- Syntax highlighting support
- Professional typography
- Command line interface
- pulldown-cmark for Markdown parsing
- syntect for syntax highlighting
- headless_chrome for PDF generation
- Crimson Text and Inter fonts