md-to-pdf
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMarkdown to PDF
Markdown转PDF
Converts markdown files to beautifully formatted PDFs using crossnote (same engine as mcp-printer).
使用crossnote(与mcp-printer相同的引擎)将Markdown文件转换为格式精美的PDF。
Features
功能特性
- Mermaid diagrams — Flowcharts, sequence diagrams, etc.
- Math equations — KaTeX rendering
- Syntax highlighting — GitHub theme
- Page numbers — Automatic footer with page X / Y
- GitHub-light theme — Clean, print-optimized styling
- Mermaid图表 — 支持流程图、时序图等
- 数学公式 — 基于KaTeX渲染
- 语法高亮 — 采用GitHub主题
- 页码 — 自动添加“第X页/共Y页”页脚
- GitHub-light主题 — 简洁、适配打印的样式
Usage
使用方法
bash
~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs input.md # Creates input.pdf
~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs input.md output.pdf # Custom output name
~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs input.md --open # Open after creatingbash
~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs input.md # 生成input.pdf
~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs input.md output.pdf # 自定义输出文件名
~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs input.md --open # 生成后打开文件Options
选项
| Flag | Description |
|---|---|
| Open the PDF after creating |
| Specify output filename |
| 参数 | 说明 |
|---|---|
| 生成后打开PDF文件 |
| 指定输出文件名 |
Requirements
依赖要求
- Chrome or Chromium — Auto-detected on macOS/Linux
- Node.js — For running the script
- Dependencies — Run in the skill directory once
npm install
- Chrome或Chromium — 在macOS/Linux系统中会自动检测
- Node.js — 用于运行脚本
- 依赖包 — 需在技能目录中运行一次
npm install
How It Works
工作原理
- Uses crossnote (Markdown Preview Enhanced engine)
- Injects page numbering config into front-matter
- Renders via Chrome/Puppeteer
- Supports Mermaid, math, code highlighting out of the box
- 使用crossnote(与mcp-printer相同的引擎)
- 在前置元数据中注入页码配置
- 通过Chrome/Puppeteer进行渲染
- 原生支持Mermaid图表、数学公式和代码高亮
Examples
示例
bash
undefinedbash
undefinedQuick conversion
快速转换
~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs README.md
~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs README.md
Spec document for sharing
生成用于分享的文档
~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs spec.md spec-v2.pdf --open
~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs spec.md spec-v2.pdf --open
Multiple files
批量转换多个文件
for f in docs/*.md; do ~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs "$f"; done
undefinedfor f in docs/*.md; do ~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs "$f"; done
undefinedMermaid Example
Mermaid示例
Include in your markdown:
markdown
```mermaid
graph TD
A[Start] --> B{Decision}
B -->|Yes| C[Do something]
B -->|No| D[Do something else]
```The diagram will render as a graphic in the PDF.
在Markdown中添加以下内容:
markdown
```mermaid
graph TD
A[Start] --> B{Decision}
B -->|Yes| C[Do something]
B -->|No| D[Do something else]
```图表将在PDF中渲染为图形。
Printing
打印
If the user wants to print the PDF, use the skill after generating.
/printWorkflow decision:
| User intent | Action |
|---|---|
| "Convert to PDF" | Keep the PDF |
| "Print this markdown" | Generate PDF → print with |
| "Create a PDF and print it" | Keep the PDF, also print |
When printing is the goal (not the PDF itself), delete the PDF after printing:
bash
undefined如果用户需要打印PDF,生成后可使用技能。
/print工作流决策:
| 用户意图 | 操作 |
|---|---|
| "转换为PDF" | 保留PDF文件 |
| "打印此Markdown" | 生成PDF → 使用 |
| "创建PDF并打印" | 保留PDF文件,同时进行打印 |
当主要需求是打印(而非保留PDF)时,打印完成后删除PDF:
bash
undefinedGenerate, print, cleanup
生成、打印、清理
~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs doc.md
~/.claude/skills/print/scripts/print doc.pdf
rm doc.pdf
The `/print` skill handles double-sided and b&w defaults automatically.~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs doc.md
~/.claude/skills/print/scripts/print doc.pdf
rm doc.pdf
`/print`技能会自动处理双面打印和黑白打印的默认设置。Alias (Optional)
别名(可选)
Add to your shell profile:
bash
alias md-to-pdf='~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs'将以下内容添加到你的Shell配置文件中:
bash
alias md-to-pdf='~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs'