pdf-creator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PDF 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.pdf
Batch 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 ./pdfs

macOS 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 TypePrimaryFallbacks
Body textSongti SCSimSun, STSong, Noto Serif CJK SC
HeadingsHeiti SCSimHei, STHeiti, Noto Sans CJK SC
脚本使用以下中文字体(包含备选字体):
字体类型主字体备选字体
正文字体Songti SCSimSun, STSong, Noto Serif CJK SC
标题字体Heiti SCSimHei, 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

常见使用场景

  1. Legal documents: Trademark filings, contracts, evidence lists
  2. Reports: Business reports, technical documentation
  3. Formal letters: Official correspondence requiring print format
  1. 法律文档: 商标申请、合同、证据清单
  2. 报告: 商务报告、技术文档
  3. 正式信函: 需要打印格式的官方信函

Troubleshooting

问题排查

Problem: Chinese characters display as boxes Solution: Ensure Songti SC or other Chinese fonts are installed on the system
Problem:
weasyprint
import error Solution: Run with
uv run --with weasyprint --with markdown
to ensure dependencies
问题: 中文字符显示为方框 解决方案: 确保系统已安装Songti SC或其他中文字体
问题:
weasyprint
导入错误 解决方案: 使用
uv run --with weasyprint --with markdown
运行以确保依赖已安装