md2pdf2

Generate beautiful, professionally styled PDF documents from Markdown content using customizable Handlebars (HBS) templates and the md2pdf2 CLI tool. Use this skill whenever the user wants to convert markdown to PDF, create a styled PDF report/document from text or markdown, generate a PDF with a custom template or theme, produce professional documents (resumes, reports, newsletters, invoices, briefs) as PDFs from markdown input. Trigger this skill even when the user just says "create a PDF", "export to PDF", "make a nice PDF", or provides markdown and wants a polished document output. Prefer this skill over the plain pdf skill when template customization or markdown-to-PDF conversion is the core need.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "md2pdf2" with this command: npx skills add areai51/md2pdf2/areai51-md2pdf2-md2pdf2

MD2PDF2 Skill

Convert Markdown to beautiful, professionally styled PDFs using the md2pdf2 CLI tool with Handlebars templates.

Overview

md2pdf2 is a Node.js CLI tool that converts Markdown → HTML (via HBS template) → PDF using Puppeteer. It supports:

  • Custom .hbs Handlebars templates with {{{content}}} for markdown body
  • CSS styling (inline or external)
  • PDF format options (A4, Letter, etc.)
  • Frontmatter metadata (title, author, date, etc.)
  • Built-in templates: default, modern, minimal, newsletter, resume

Workflow

Step 1 — Understand the request

Determine:

  1. Content: Does the user have markdown, or should you generate it from their description?
  2. Template/Style: Which built-in template fits, or should you create a custom .hbs?
  3. Output filename: Default to output.pdf unless specified.

Step 2 — Set up the environment

# Install md2pdf2 globally (or use npx)
npm install -g md2pdf2 2>/dev/null || true
# Verify
which md2pdf2 || npx md2pdf2 --version

If global install fails (permissions), use npx md2pdf2 in all commands.

Step 3 — Prepare files in /home/claude/

a) Write markdown content to /home/claude/input.md

Always include YAML frontmatter for metadata:

---
title: Document Title
author: Author Name
date: 2024-01-01
---

# Your Content Here

b) Create or select a template

For custom templates, write a .hbs file. See the Template Guide below.

For built-in templates, pass --template <name> (default, modern, minimal, newsletter, resume).

c) Write config if needed to /home/claude/md2pdf2.config.js:

export default {
  template: './custom.hbs',   // path to HBS template (optional)
  pdfOptions: {
    format: 'A4',             // 'A4' | 'Letter' | 'Legal'
    margin: { top: '2cm', right: '2cm', bottom: '2cm', left: '2cm' }
  }
}

Step 4 — Run the conversion

cd /home/claude && npx md2pdf2 convert input.md -o /mnt/user-data/outputs/output.pdf
# With custom template:
npx md2pdf2 convert input.md --template custom.hbs -o /mnt/user-data/outputs/output.pdf
# With built-in template name:
npx md2pdf2 convert input.md --template modern -o /mnt/user-data/outputs/output.pdf

Step 5 — Present the file

Use present_files with the output path.


Template Guide

Minimal valid HBS template

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <style>
    body { font-family: Georgia, serif; max-width: 800px; margin: 0 auto; padding: 40px; }
    h1 { color: #2c3e50; }
  </style>
</head>
<body>
  <h1>{{title}}</h1>
  <p>{{author}} — {{date}}</p>
  {{{content}}}
</body>
</html>

Key variables available in templates:

  • {{{content}}} — rendered HTML from markdown (use triple braces — no escaping)
  • {{title}} — from frontmatter
  • {{author}} — from frontmatter
  • {{date}} — from frontmatter
  • {{> partialName}} — include a partial from templates/parts/

Built-in Handlebars helpers:

  • {{currentDate}} — returns current date (e.g., "January 15, 2024")
  • {{slice str start end}} — slice a string (e.g., {{slice title 0 1}} for first character)
  • {{hasPartial "name"}} — check if a partial exists

Beautiful template recipes

See templates/ folder in this skill for ready-to-use templates:

  • professional-report.hbs — corporate report with cover page
  • resume.hbs — clean two-column CV layout
  • newsletter.hbs — styled newsletter with header/footer

Built-in Templates Quick Reference

TemplateBest For
defaultGeneral purpose, clean
modernBold, colorful, Inter font
minimalSimple serif, academic
newsletterEmail-style newsletter
resumeCV/resume formatting

Troubleshooting

md2pdf2: command not found → Use npx md2pdf2 instead.

Puppeteer/Chrome errors in sandbox → Add --no-sandbox flag if supported, or check if headless Chrome is available: google-chrome --version || chromium --version.

Template not found → Ensure the .hbs file path is relative to the working directory where you run the command.

Styles not applying → Check CSS is inside <style> tags in the HBS template, not external (external CSS won't load in Puppeteer's sandboxed env without explicit file:// paths).


Example: Full workflow

# 1. Write content
cat > /home/claude/input.md << 'EOF'
---
title: Q4 Sales Report
author: Finance Team
date: 2024-12-31
---

## Executive Summary
Revenue grew 23% YoY...

## Key Metrics
| Metric | Value |
|--------|-------|
| Revenue | $4.2M |
| Growth | 23% |
EOF

# 2. Convert with modern template
cd /home/claude && npx md2pdf2 convert input.md --template modern -o /mnt/user-data/outputs/q4-report.pdf

# 3. Verify
ls -la /mnt/user-data/outputs/q4-report.pdf

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

openclaw-version-monitor

监控 OpenClaw GitHub 版本更新,获取最新版本发布说明,翻译成中文, 并推送到 Telegram 和 Feishu。用于:(1) 定时检查版本更新 (2) 推送版本更新通知 (3) 生成中文版发布说明

Archived SourceRecently Updated
Coding

ask-claude

Delegate a task to Claude Code CLI and immediately report the result back in chat. Supports persistent sessions with full context memory. Safe execution: no data exfiltration, no external calls, file operations confined to workspace. Use when the user asks to run Claude, delegate a coding task, continue a previous Claude session, or any task benefiting from Claude Code's tools (file editing, code analysis, bash, etc.).

Archived SourceRecently Updated
Coding

ai-dating

This skill enables dating and matchmaking workflows. Use it when a user asks to make friends, find a partner, run matchmaking, or provide dating preferences/profile updates. The skill should execute `dating-cli` commands to complete profile setup, task creation/update, match checking, contact reveal, and review.

Archived SourceRecently Updated