A CLI tool that converts Markdown to PDF using customizable templates — think Astro, but for PDFs.
- Convert Markdown to PDF with a single command
- Customizable templates with layout, styling, and components
- Supports multiple output formats (letter, a4, etc.)
- Template inheritance and partials
- Frontmatter support for metadata
- Built-in template engine (Handlebars-like syntax)
- CLI flags for quick customization
- Watch mode for development
# Install globally (once published)
npm install -g md2pdf2
# Or use npx
npx md2pdf2 convert input.md -o output.pdf
# Initialize a new project with sample files
md2pdf2 init
# With a custom template
md2pdf2 convert input.md --template my-template.hbs -o output.pdf
# Dev mode with live preview
md2pdf2 dev input.mdInstall the md2pdf2 skill for Claude Code, Amp, OpenCode etc:
npx skills add areai51/md2pdf2This adds the skill to your Claude Code environment, enabling intelligent PDF generation with automatic template selection and markdown formatting.
Use md2pdf2 as an MCP server with AI agents:
# Using npx (no installation required)
npx md2pdf2-mcp
# Or install globally
npm install -g md2pdf2
md2pdf2-mcpAdd to your claude_desktop_config.json:
{
"mcpServers": {
"md2pdf2": {
"command": "npx",
"args": ["md2pdf2-mcp"]
}
}
}- convert: Convert a Markdown file to PDF
- convertMarkdown: Convert a Markdown string to PDF
- listTemplates: List available built-in templates
Agents can now use the MCP tools to convert markdown:
{
"tool": "convert",
"arguments": {
"input": "./document.md",
"output": "./document.pdf",
"template": "./templates/modern.hbs",
"format": "A4"
}
}Start a live preview server to see your markdown rendered in different templates:
md2pdf2 dev input.md --port 3456Opens a browser with:
- Left pane: Template selector (switch between templates)
- Right pane: Live preview of your markdown
Changes to your .md file or templates auto-reload the preview.
default- Clean, professional lookmodern- Bold colors, Inter-style typographyminimal- Simple, classic serifnewsletter- Email newsletter styleresume- CV/resume formatting
my-doc/
├── content/
│ └── my-doc.md
├── templates/
│ ├── default.hbs
│ ├── parts/
│ │ └── header.hbs
│ └── styles.css
├── md2pdf2.config.js
└── package.json
Templates use handlebars-like syntax for placeholders and partials:
md2pdf2.config.js:
export default {
template: './templates/default.hbs',
style: './templates/styles.css',
pdfOptions: {
format: 'A4',
margin: { top: '1cm', right: '1cm', bottom: '1cm', left: '1cm' }
}
}# Clone and setup
git clone https://github.com/areai51/md2pdf.git
cd md2pdf
npm install
# Build
npm run build
# Test
npm test
# Link for global use
npm linkMIT