A powerful, extensible markdown to PDF converter written in Go with plugin support.
There are several tools for converting Markdown to PDF. Here's how MD-to-PDF compares:
| Feature | MD-to-PDF | Pandoc | wkhtmltopdf |
|---|---|---|---|
| Binary Size | ~12MB | ~50MB | ~100MB |
| Dependencies | None | System libs | System libs |
| Plugin System | Yes | Filters | No |
| Learning Curve | Low | High | Medium |
| Configuration | Simple YAML | Complex | Command flags |
Key differentiators:
- Zero dependencies: Single binary, no runtime requirements. Download and run.
- Plugin architecture: Extend functionality without modifying core code. Add custom transformations, content generators, and more.
- Simple configuration: Human-readable YAML config with sensible defaults. No need to memorize complex command-line flags.
- Built for Markdown: Purpose-built for Markdown-to-PDF conversion, not a general-purpose document converter.
- Fast & reliable: Built in Go for performance and reliability
- Plugin system: Extensible architecture with custom plugin support
- Rich formatting: Support for tables, code blocks, images, and more
- Mermaid diagrams: Built-in support for Mermaid diagram generation
- Configurable: Extensive customization options for fonts, margins, spacing
- Table of contents: Automatic TOC generation
- CLI interface: Easy-to-use command-line interface with sensible defaults
curl -sSL https://raw.githubusercontent.com/fredcamaral/md-to-pdf/main/install.sh | bash- Download the latest release from GitHub Releases
- Extract and move the binary to your PATH
git clone https://github.com/fredcamaral/md-to-pdf.git
cd md-to-pdf
make buildConvert a markdown file to PDF:
md-to-pdf convert document.mdConvert with custom options:
md-to-pdf convert document.md \
--output custom-name.pdf \
--title "My Document" \
--author "John Doe" \
--font-size 12 \
--margins "20,20,20,20"View current configuration:
md-to-pdf config listSet configuration values:
md-to-pdf config set font.family "Times New Roman"
md-to-pdf config set page.margins "25,25,25,25"
md-to-pdf config set text.fontSize 11Reset configuration to defaults:
md-to-pdf config resetMD-to-PDF supports two types of plugins:
Modify the markdown abstract syntax tree before rendering:
type ASTTransformer interface {
Transform(node ast.Node, ctx *TransformContext) (ast.Node, error)
Priority() int
SupportedNodes() []ast.NodeKind
}Generate additional content during PDF creation:
type ContentGenerator interface {
GenerateContent(ctx *GenerationContext) error
Priority() int
}- Mermaid Plugin: Converts mermaid code blocks to PNG diagrams
- TOC Plugin: Generates table of contents
Place plugin .so files in the plugins/ directory and md-to-pdf loads them automatically.
Plugin Development Guide - Learn how to create custom plugins
| Category | Option | Default | Description |
|---|---|---|---|
| Font | font.family |
"Arial" | Font family name |
| Font | font.size |
10 | Font size in points |
| Page | page.size |
"A4" | Page size (A4, Letter, Legal) |
| Page | page.margins |
"20,20,20,20" | Margins (top,right,bottom,left) |
| Text | text.lineSpacing |
1.2 | Line spacing multiplier |
| Mermaid | mermaid.theme |
"default" | Mermaid theme |
| Mermaid | mermaid.scale |
2.2 | Mermaid diagram scale |
md-to-pdf convert [file] [flags]--output, -o: Output PDF file name--title: Document title--author: Document author--subject: Document subject--keywords: Document keywords--font-family: Font family--font-size: Font size--page-size: Page size (A4, Letter, Legal)--margins: Page margins "top,right,bottom,left"--line-spacing: Text line spacing--mermaid-theme: Mermaid theme--mermaid-scale: Mermaid scale factor--plugins-dir: Plugins directory--verbose, -v: Verbose output
md-to-pdf config list # List all configuration
md-to-pdf config set <key> <value> # Set configuration value
md-to-pdf config reset # Reset to defaults# Convert with defaults
md-to-pdf convert README.md
# Convert with custom output name
md-to-pdf convert README.md -o documentation.pdf# Larger font and margins
md-to-pdf convert document.md \
--font-size 12 \
--margins "30,30,30,30" \
--line-spacing 1.5
# Different font family
md-to-pdf convert document.md \
--font-family "Times New Roman"md-to-pdf convert report.md \
--title "Monthly Report" \
--author "Jane Smith" \
--subject "Business Analytics" \
--keywords "report,analytics,monthly"# Custom mermaid settings
md-to-pdf convert flowchart.md \
--mermaid-theme dark \
--mermaid-scale 3.0- Headers (H1-H6)
- Emphasis (bold, italic, strikethrough)
- Lists (ordered, unordered, nested)
- Links (inline, reference)
- Images (local files, embedded)
- Code blocks (syntax highlighting)
- Tables (with alignment)
- Blockquotes
- Horizontal rules
- Mermaid diagrams (via plugin)
- Go 1.21 or later
- Make
- Git
make build # Build binary
make build-plugins # Build plugins
make test # Run tests
make clean # Clean build artifactsmd-to-pdf/
├── cmd/ # CLI commands
├── internal/
│ ├── core/ # Core conversion engine
│ ├── parser/ # Markdown parsing
│ ├── renderer/ # PDF rendering
│ ├── plugins/ # Plugin system
│ └── config/ # Configuration management
├── examples/
│ └── plugins/ # Example plugins
├── pkg/
│ └── plugin/ # Public plugin API
└── plugins/ # Plugin directory and development guide
Contributions are welcome! See CONTRIBUTING.md for guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
See CHANGELOG.md for version history and changes.
You can use a shell loop or find command:
# Convert all markdown files in current directory
for f in *.md; do md-to-pdf convert "$f"; done
# Convert recursively
find . -name "*.md" -exec md-to-pdf convert {} \;You can customize styling in two ways:
-
Command-line flags for one-time changes:
md-to-pdf convert doc.md --font-size 12 --margins "30,30,30,30" -
Configuration file for persistent settings:
md-to-pdf config set font.family "Times New Roman" md-to-pdf config set text.fontSize 12
- Place
.soplugin files in theplugins/directory (or specify with--plugins-dir) - md-to-pdf loads plugins automatically on conversion
- See the Plugin Development Guide for creating custom plugins
The configuration file is stored at:
- Linux/macOS:
~/.config/md-to-pdf/config.yaml - Windows:
%APPDATA%\md-to-pdf\config.yaml
View the current config location and values with:
md-to-pdf config listmd-to-pdf config resetThis removes all custom settings and restores default settings.