pdf-creator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePDF Creator
PDF生成工具
Create professional PDF documents from markdown with proper Chinese font support.
从markdown创建支持中文字体的专业PDF文档。
Quick Start
快速开始
Convert a single markdown file:
bash
uv run --with weasyprint --with markdown scripts/md_to_pdf.py input.md output.pdfBatch convert multiple files:
bash
uv run --with weasyprint --with markdown scripts/batch_convert.py *.md --output-dir ./pdfs转换单个markdown文件:
bash
uv run --with weasyprint --with markdown scripts/md_to_pdf.py input.md output.pdf批量转换多个文件:
bash
uv run --with weasyprint --with markdown scripts/batch_convert.py *.md --output-dir ./pdfsmacOS Environment Setup
macOS环境配置
If encountering library errors, set these environment variables first:
bash
export DYLD_LIBRARY_PATH="/opt/homebrew/lib:$DYLD_LIBRARY_PATH"
export PKG_CONFIG_PATH="/opt/homebrew/lib/pkgconfig:$PKG_CONFIG_PATH"如果遇到库错误,请先设置以下环境变量:
bash
export DYLD_LIBRARY_PATH="/opt/homebrew/lib:$DYLD_LIBRARY_PATH"
export PKG_CONFIG_PATH="/opt/homebrew/lib/pkgconfig:$PKG_CONFIG_PATH"Font Configuration
字体配置
The scripts use these Chinese fonts (with fallbacks):
| Font Type | Primary | Fallbacks |
|---|---|---|
| Body text | Songti SC | SimSun, STSong, Noto Serif CJK SC |
| Headings | Heiti SC | SimHei, STHeiti, Noto Sans CJK SC |
脚本使用以下中文字体(包含备选字体):
| 字体类型 | 主字体 | 备选字体 |
|---|---|---|
| 正文字体 | Songti SC | SimSun, STSong, Noto Serif CJK SC |
| 标题字体 | Heiti SC | SimHei, STHeiti, Noto Sans CJK SC |
Output Specifications
输出规格
- Page size: A4
- Margins: 2.5cm top/bottom, 2cm left/right
- Body font: 12pt, 1.8 line height
- Max file size: Designed to stay under 2MB for form submissions
- 页面尺寸: A4
- 边距: 上下2.5厘米,左右2厘米
- 正文字体: 12号,1.8倍行高
- 最大文件大小: 为适配表单提交,设计为不超过2MB
Common Use Cases
常见使用场景
- Legal documents: Trademark filings, contracts, evidence lists
- Reports: Business reports, technical documentation
- Formal letters: Official correspondence requiring print format
- 法律文档: 商标申请、合同、证据清单
- 报告: 商务报告、技术文档
- 正式信函: 需要打印格式的官方信函
Troubleshooting
问题排查
Problem: Chinese characters display as boxes
Solution: Ensure Songti SC or other Chinese fonts are installed on the system
Problem: import error
Solution: Run with to ensure dependencies
weasyprintuv run --with weasyprint --with markdown问题: 中文字符显示为方框
解决方案: 确保系统已安装Songti SC或其他中文字体
问题: 导入错误
解决方案: 使用运行以确保依赖已安装
weasyprintuv run --with weasyprint --with markdown