by lxsssssss
# Add to your Claude Code skills
git clone https://github.com/lxsssssss/pdf-translateGuides for using ai agents skills like pdf-translate.
See how pdf-translate compares with popular alternatives.
pdf-translate is an open-source ai agents skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by lxsssssss. It has 50 GitHub stars.
pdf-translate's catalog security scan is still queued. You can run an instant dependency and prompt-injection check now with the "Scan for vulnerabilities" button above.
Clone the repository with "git clone https://github.com/lxsssssss/pdf-translate" and add it to your Claude Code skills directory (see the Installation section above). pdf-translate ships a SKILL.md manifest, so compatible agents can discover and load it automatically.
pdf-translate is primarily written in Python. It is open-source under lxsssssss on GitHub, so you can review or fork the full source.
Yes. SkillsLLM lists many other AI Agents skills you can browse and compare side by side. Open the AI Agents category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh pdf-translate against similar tools.
No comments yet. Be the first to share your thoughts!
Unlocks once the catalog security scan passes (runs nightly).
⚠️ Third-Party Software Notice
This skill is third-party open-source software developed and hosted independently on GitHub. SkillsLLM is an informational directory and does not control or maintain the underlying repository.
Any security checks, ratings, or warnings displayed by SkillsLLM are automated and limited in scope. They do not constitute a security certification or guarantee that the software is safe, error-free, or free from malicious code, vulnerabilities, compromised dependencies, or prompt-injection risks.
Review the source code, permissions, dependencies, and configuration before installing or running any third-party skill. Use is at your own risk. To the maximum extent permitted by applicable law, SkillsLLM is not liable for losses arising from third-party software.
The deep catalog scan for this skill is still queued. Run an instant dependency check now instead.
当用户需要翻译 PDF 文档,且要求必须完整保留原始版面格式、公文表头、目录、双语表格、签章栏、插图物理尺寸并最终输出为高保真矢量 PDF 文件时,使用此 Skill。
[!IMPORTANT] 四大核心铁律(杜绝机翻乱码、长文档幻觉、跨页溢出与图片排版变形):
- 严禁脑补,严格忠实直译 (Strict Faithful Translation & Zero Hallucination):
- 不得压缩或遗漏条款:逐条忠实翻译每一个一级、二级、三级子条款(如法定资质证照清单 2.1.1~2.1.8、年限指标、年产能门槛 150,000 吨、分卷装订规则 Volume 2A/2B 等),坚决禁止主观总结或合并条款;
- 坚决禁止虚构常识:严禁凭常识脑补原文不存在的交付程序、装订份数、银行授信金额或办事流程(例如原文未写具体金额则绝对禁止编造 1,000,000 KWD,无 5.3 节则绝对不可添加 5.3 节);
- 表格格式 1:1 忠实还原:官方附表(如 Appendix-1 至 Appendix-6)的列名、行高、选项框、备注及签字盖章区必须严格对齐原件,严禁用自创的“申报核对清单 (Checklist)”或通用表格粗糙代替。
- 几何探针与视觉锚点测量铁律 (Geometry Probe & Visual Anchor Measurement):
- 绝对禁止经验主义猜度尺寸:严禁在未测量原件几何信息的情况下,随意给插图或表格加上
max-height: 220px等主观限制,导致原图严重缩水变形或比例失调;- 原图物理坐标与尺寸 1:1 提取:提取图片时必须调用
page.get_image_rects(xref)获取原图在页面上的实际width、height以及x0, y0,并在 HTML 中严格以真实物理尺寸呈现(如原件宽 218.9pt、高 322.4pt,HTML 中必须按照该物理尺寸渲染);- 几何线条与装饰框高保真复刻:通过
page.get_drawings()提取所有几何元素(如顶会论文标题框的 4pt 粗黑顶线与 1pt 细底线、长度 143.5pt 的左对齐短横脚注线),严禁用通用单薄的 100% 宽度边框粗暴替代;- 中文信息密度补偿与垂直基线对齐:中文字符信息密度通常比西文高 20%~35%,必须记录关键文字块的垂直基准起点
y0(如摘要标题、正文、章节起始与脚注线位置),通过微调行高(line-height: 1.35~1.45)、段落间距(margin)以及灵活运用网格与绝对定位,确保中文版面的视觉重心与垂直基线与原件严密锚定,杜绝页面下半部分突兀大面积留白;- 首页页眉页脚特殊规则:大部分顶会论文(NIPS/ICML/CVPR 等)或官方公文首页(Page 1)不编排页码,底部通常为会议发表信息或官方备案行,严禁在第一页机械添加页码。
- 两阶段解耦与分块生成 (Schema-First & Chunked Pipeline):
- 数据与排版分离:长文档翻译时,优先提取页面结构化数据(条款清单、参数字典、表格行列),再灌入标准化 HTML 模板,严禁一边长篇自由发挥一边写标签;
- 单批次生成严禁超过 10 页:超过 10 页的文档强制按 10 页为单位拆分为独立模块(如
part1_pages.py,part2_pages.py),避免模型在中后段注意力衰减导致失控。- 生成后对比质检与用户确认关卡 (Mandatory Audit & User Preview Before Commit):
- PDF 渲染生成后,绝不允许直接交付给用户,必须运行技能内置的
scripts/audit_pdf.py执行页码、矢量层、条款差集与敏感词全面扫描;- 渲染生成 1:1 并排对比图(PNG),必须在对话中直接展示关键页面对比效果供用户审阅确认,在获得用户明确许可前严禁擅自 Git Commit 或推送!
当收到翻译 PDF 任务时,Agent 需严格遵循以下 5 步标准化闭环作业流程:
使用 Python (fitz / PyMuPDF) 全面探测文档物理尺寸、插图尺寸、装饰线与关键文本块基线坐标:
import fitz
doc = fitz.open("path/to/document.pdf")
print("Total pages:", len(doc))
for i, page in enumerate(doc):
print(f"\n=== PAGE {i+1} rect: {page.rect} ===")
# 1. 探测图片物理尺寸与位置
for img in page.get_images():
for r in page.get_image_rects(img[0]):
print(f" Image xref {img[0]}: w={r.width:.1f}, h={r.height:.1f}, (x0={r.x0:.1f}, y0={r.y0:.1f})")
# 2. 探测几何线条与装饰边框
for d in page.get_drawings():
r = d['rect']
if r.width > 30:
print(f" Line: w={r.width:.1f}, h={r.height:.1f}, (x0={r.x0:.1f}, y0={r.y0:.1f})")
# 3. 探测核心文本块垂直基准起点 y0
for b in page.get_text("blocks"):
if b[4].strip():
print(f" Block ({b[0]:.1f}, {b[1]:.1f}, {b[2]:.1f}, {b[3]:.1f}): {b[4].strip()[:40]}")
# 若总页数 > 10 页,强制制定分块规划(如 Part 1: P1~10, Part 2: P11~20 ...)
利用标准 HTML5 + CSS @page 打印样式进行 1:1 页面映射重构:
@page(如 US Letter size: 8.5in 11in; 或 A4 size: 210mm 297mm;):
@page {
size: 8.5in 11in;
margin: 0;
}
.page {
width: 8.5in;
height: 11in;
max-height: 11in;
padding: 72pt 108pt 72pt 108pt;
page-break-after: always;
position: relative;
box-sizing: border-box;
display: flex;
flex-direction: column;
overflow: hidden; /* 严禁内部元素撑爆高度触发打印机额外分页 */
}
.content-area {
flex: 1;
overflow: hidden;
}
w 和 h 设定图片的 width 与 height(如 width: 218.9pt; height: 322.4pt;),绝对禁止用经验值限制!调用技能内置渲染脚本直接生成纯矢量 PDF,内置 JavaScript 探针会自动检测是否有任何页面产生高度溢出:
python "e:\antigravity_workspace\univ\.agent\skills\pdf-translate\scripts\render_pdf.py" "path/to/full_doc.html" "path/to/output_full.pdf"
生成 PDF 后,必须运行技能内置的 audit_pdf.py 自动化对比工具并生成对比图:
python "e:\antigravity_workspace\univ\.agent\skills\pdf-translate\scripts\audit_pdf.py" --src "path/to/source.pdf" --tgt "path/to/output_full.pdf"
该工具全自动执行 4 大流水线:
用户视觉确认门禁 (User Confirmation Gate):
.agent/skills/pdf-translate/scripts/render_pdf.py
.page 物理高度,避免跨页溢出。.agent/skills/pdf-translate/scripts/audit_pdf.py
High-Fidelity Vector PDF Translation, Layout Reconstruction & Automated Audit Engine for AI Agents.
基于大语言模型直译、矢量排版重构、浏览器溢出探针与自动化双向对比自愈的高保真 PDF 翻译技能。
实测案例:现代深度学习与大模型开山之作《Attention Is All You Need》(arXiv:1706.03762),包含多作者机构矩阵、精准边栏学术水印、双栏摘要、数学脚注及严格版面限高。


传统的文档翻译工具(如通用机翻、常规 OCR 导出)在面对工程标书、跨国商务合同、法定资质证书、学术白皮书等严肃公文时,常常面临四大致命难题:
pdf-translate 专为解决上述痛点而生,结合大模型精准语义提取与前端 CSS 矢量打印控制,确保翻译结果达到正式出版与官方公文交付级标准。
.page 容器的 scrollHeight 与 clientHeight。scripts/audit_pdf.py)
flowchart TD
A["原始 PDF 文档"] --> B["步骤 1: PyMuPDF 结构探测与分块规划"]
B --> C["步骤 2: 两阶段数据契约抽取与严谨直译"]
C --> D["步骤 3: 现代化 HTML5 + CSS @page 矢量重构"]
D --> E["步骤 4: Playwright 无头渲染 + JS 溢出探针 (render_pdf.py)"]
E --> F["生成目标矢量 PDF"]
F --> G["步骤 5: audit_pdf.py 自动化审计对比"]
G -->|"未通过: 发现溢出 / 遗漏 / 编号不符"| D
G -->|"通过: 1:1 完美匹配 且 0 报错"| H["正式交付发布"]
pdf-translate/
├── .github/
│ ├── workflows/ci.yml # 自动化 CI 测试工作流
│ └── ISSUE_TEMPLATE/ # 社区 Bug 与 Feature 规范模板
├── SKILL.md # Antigravity / AI Agent 核心技能指令与约束规范 (中文版)
├── SKILL_EN.md # Core Skill Definition & Zero-Hallucination SOP (English Version)
├── requirements.txt # 核心 Python 依赖项
├── LICENSE # MIT 开源协议
├── README.md # 简体中文说明文档
├── README_EN.md # English Documentation
├── assets/ # 官方公文 1:1 真实案例对比图
├── examples/ # 开箱即测示例与一键体验脚本
│ ├── sample_doc.html # 包含双语公文表头、表格与签章的标准 A4 测试模板
│ └── quick_demo.py # 一键端到端「Playwright 渲染 + 自动化审计」测试脚本
└── scripts/
├── audit_pdf.py # 1:1 页对页结构、条款双向 Diff 与敏感词自动化审计引擎
└── render_pdf.py # 基于 Playwright 的高保真矢量 PDF 渲染脚本 (内置 JS 溢出探针)
git clone https://github.com/lxsssssss/pdf-translate.git
cd pdf-translate
pip install -r requirements.txt
playwright install chromium
注:Windows 环境下亦支持直接调用系统自带的
msedge浏览器信道。
无需准备任何复杂环境,直接运行项目内置的端到端体验脚本:
python examples/quick_demo.py
终端将依次执行:调用 Playwright 渲染矢量 PDF ➔ 触发 JS 页面高度防溢出探针 ➔ 执行 PyMuPDF 纯矢量层与条款一致性审计 ➔ 输出绿标 PASS 报告!
render_pdf.py)将排版好的 HTML 源码渲染为物理隔离的矢量 PDF:
# 基础渲染
python scripts/render_pdf.py input.html output.pdf
# 开启严格模式 (若检测到任何页面高度溢出则立即抛出异常阻断)
python scripts/render_pdf.py input.html output.pdf --strict-overflow
audit_pdf.py)比对原版 PDF 与翻译后 PDF 的页码、矢量层、条款编号与文本完整性:
# 基础对比审计
python scripts/audit_pdf.py --src original.pdf --tgt translated.pdf
# 严格模式 (任何警告均触发非零返回码)
python scripts/audit_pdf.py --src original.pdf --tgt translated.pdf --strict
# 输出结构化 JSON 审计报告 (便于 CI/CD 或 Agent 自动化解析)
python scripts/audit_pdf.py --src original.pdf --tgt translated.pdf --json-out audit_report.json
本项目设计为跨平台、零依赖摩擦的通用 Agent 技能,原生兼容目前主流 AI 编程助手与大模型智能体环境:
| 平台 / 工具 | 部署路径 / 形式 | 核心支持说明 |
|---|---|---|
| Google Antigravity | .agent/skills/pdf-translate/ |
原生 Skill 识别,自动探测与 5 步 SOP 闭环 |
| Claude Code | .claude/skills/pdf-translate/ 或全局规则 |
遵循 SKILL_EN.md 规则与两阶段零幻觉契约 |
| Cursor | .cursorrules 或 .cursor/rules/ |
代码生成严格遵循 @page 限高与纯矢量布局 |
| Windsurf (Cascade) | .windsurfrules |
自动化调用 render_pdf.py 与 audit_pdf.py 自愈 |
| OpenAI Codex | Custom Instructions / Action | 结构化数据提取 + 模板化填充双阶段工作流 |
| WorkBuddy | 智能体工作流 / 技能中心插件 | 商务公文、外贸标书 1:1 翻译自动化作业 |
| DeepSeek (V3 / R1) | 系统提示词 (System Prompt) | 深度推理提取条款树,严禁虚构与脑补条款 |
直接将本项目拷贝至工作区的 .agent/skills/pdf-translate 目录下:
your-project/
└── .agent/
└── skills/
└── pdf-translate/
├── SKILL.md
├── SKILL_EN.md
└── scripts/
在会话中提示 “帮我把这份文件翻译为中文,保持原排版并输出为 PDF”,Agent 将自动激活该 Skill 并执行闭环工作流。
将 SKILL_EN.md 导入 Claude 项目自定义指令或配置为专属技能:
claude config add-skill pdf-translate ./SKILL_EN.md
本项目根目录已内置配置好的 .cursorrules 与 .windsurfrules,直接打开本项目所在目录即可自动生效;或将规则内容直接复制进你现有工程的全局规则中。
将 SKILL.md(或 SKILL_EN.md)核心铁律与 SOP 粘贴为 Agent 系统的 System Prompt,并开放 Python 终端权限以供调用 scripts/render_pdf.py 与 scripts/audit_pdf.py。
本项目采用 MIT 许可证。