md-to-pdf

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Markdown 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 creating
bash
~/.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

选项

FlagDescription
--open
,
-O
Open the PDF after creating
-o FILE
Specify output filename
参数说明
--open
,
-O
生成后打开PDF文件
-o FILE
指定输出文件名

Requirements

依赖要求

  • Chrome or Chromium — Auto-detected on macOS/Linux
  • Node.js — For running the script
  • Dependencies — Run
    npm install
    in the skill directory once
  • Chrome或Chromium — 在macOS/Linux系统中会自动检测
  • Node.js — 用于运行脚本
  • 依赖包 — 需在技能目录中运行一次
    npm install

How It Works

工作原理

  1. Uses crossnote (Markdown Preview Enhanced engine)
  2. Injects page numbering config into front-matter
  3. Renders via Chrome/Puppeteer
  4. Supports Mermaid, math, code highlighting out of the box
  1. 使用crossnote(与mcp-printer相同的引擎)
  2. 在前置元数据中注入页码配置
  3. 通过Chrome/Puppeteer进行渲染
  4. 原生支持Mermaid图表、数学公式和代码高亮

Examples

示例

bash
undefined
bash
undefined

Quick 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
undefined
for f in docs/*.md; do ~/.claude/skills/md-to-pdf/scripts/md-to-pdf.mjs "$f"; done
undefined

Mermaid 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
/print
skill after generating.
Workflow decision:
User intentAction
"Convert to PDF"Keep the PDF
"Print this markdown"Generate PDF → print with
/print
→ delete PDF
"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 → 使用
/print
技能打印 → 删除PDF
"创建PDF并打印"保留PDF文件,同时进行打印
当主要需求是打印(而非保留PDF)时,打印完成后删除PDF:
bash
undefined

Generate, 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'