markdown-to-pdf

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

markdown-to-pdf

markdown-to-pdf

Convert markdown files to professionally-styled PDF documents.
将Markdown文件转换为具有专业样式的PDF文档。

Installation Required

需要安装

bash
cd .claude/skills/markdown-to-pdf
npm install
Dependencies:
md-to-pdf
(includes Puppeteer, auto-downloads Chromium ~200MB)
bash
cd .claude/skills/markdown-to-pdf
npm install
依赖项:
md-to-pdf
(包含Puppeteer,会自动下载约200MB的Chromium)

Quick Start

快速开始

bash
undefined
bash
undefined

Basic conversion

基础转换

node .claude/skills/markdown-to-pdf/scripts/convert.cjs
--file ./README.md
node .claude/skills/markdown-to-pdf/scripts/convert.cjs
--file ./README.md

Custom output path

自定义输出路径

node .claude/skills/markdown-to-pdf/scripts/convert.cjs
--file ./doc.md
--output ./output/doc.pdf
node .claude/skills/markdown-to-pdf/scripts/convert.cjs
--file ./doc.md
--output ./output/doc.pdf

Custom styling

自定义样式

node .claude/skills/markdown-to-pdf/scripts/convert.cjs
--file ./report.md
--style ./custom-style.css
undefined
node .claude/skills/markdown-to-pdf/scripts/convert.cjs
--file ./report.md
--style ./custom-style.css
undefined

CLI Options

CLI选项

OptionRequiredDescription
--file <path>
YesInput markdown file
--output <path>
NoOutput PDF path (default: input name + .pdf)
--style <path>
NoCustom CSS file
选项是否必填描述
--file <path>
输入的Markdown文件路径
--output <path>
输出PDF的路径(默认:输入文件名 + .pdf)
--style <path>
自定义CSS文件路径

Output Format (JSON)

输出格式(JSON)

json
{
  "success": true,
  "input": "/path/to/input.md",
  "output": "/path/to/output.pdf",
  "pages": 5
}
json
{
  "success": true,
  "input": "/path/to/input.md",
  "output": "/path/to/output.pdf",
  "pages": 5
}

Default Styling

默认样式

  • GitHub-flavored markdown
  • Code syntax highlighting (highlight.js)
  • Sans-serif body (system fonts)
  • Monospace code blocks
  • A4 page size, 2cm margins
  • GitHub风格的Markdown
  • 代码语法高亮(highlight.js)
  • 无衬线正文(系统字体)
  • 等宽代码块
  • A4页面尺寸,2cm边距

Customization

自定义设置

Create custom CSS:
css
body {
  font-family: Georgia, serif;
  font-size: 12pt;
  line-height: 1.6;
}
h1 { color: #2c3e50; border-bottom: 2px solid #3498db; }
code { background: #f4f4f4; padding: 2px 6px; }
创建自定义CSS:
css
body {
  font-family: Georgia, serif;
  font-size: 12pt;
  line-height: 1.6;
}
h1 { color: #2c3e50; border-bottom: 2px solid #3498db; }
code { background: #f4f4f4; padding: 2px 6px; }

Troubleshooting

故障排除

Chromium download fails: Set
PUPPETEER_SKIP_DOWNLOAD=1
then manually install Chrome Memory issues: Large docs may need
--max-old-space-size=4096
Chromium下载失败: 设置环境变量
PUPPETEER_SKIP_DOWNLOAD=1
,然后手动安装Chrome 内存问题: 大型文档可能需要添加参数
--max-old-space-size=4096

IMPORTANT Task Planning Notes

重要任务规划说明

  • Always plan and break many small todo tasks
  • Always add a final review todo task to review the works done at the end to find any fix or enhancement needed
  • 始终规划并拆分多个小型待办任务
  • 始终添加一个最终审核的待办任务,在最后检查已完成的工作,找出需要修复或优化的地方