科学 PDF 文档翻译及双语对照工具
欢迎在 GitHub Issues 或 Telegram 用户群
有关如何贡献的详细信息,请查阅 贡献指南
更新
- [2025年2月22日] 更好的发布 CI 和精心打包的 windows-amd64 exe (由 @awwaawwa 提供)
- [2024年12月24日] 翻译器现在支持在 Xinference 上使用本地模型 (由 @imClumsyPanda 提供)
- [2024年12月19日] 现在支持非 PDF/A 文档,使用
-cp
(由 @reycn 提供) - [2024年12月13日] 额外支持后端 (由 @YadominJinta 提供)
- [2024年12月10日] 翻译器现在支持 Azure 上的 OpenAI 模型 (由 @yidasanqian 提供)
预览

在线演示 🌟
在线服务 🌟
您可以通过以下演示尝试我们的应用程序:
- 公共免费服务 在线使用,无需安装 _(推荐)_。
- 在 HuggingFace 上托管的演示
- 在 ModelScope 上托管的演示 无需安装。
请注意演示的计算资源有限,请避免滥用它们。
安装和使用
方法
针对不同的使用案例,我们提供不同的方法来使用我们的程序:
1. UV 安装
安装 Python (3.10 <= 版本 <= 3.12)
安装我们的包:
pip install uv uv tool install --python 3.12 pdf2zh
执行翻译,文件生成在 当前工作目录:
pdf2zh document.pdf
2. Windows exe
从 发布页面 下载 pdf2zh-version-win64.zip
解压缩并双击
pdf2zh.exe
运行。
3. 图形用户界面
1. 安装 Python (3.10 <= 版本 <= 3.12) 2. 安装我们的包:pip install pdf2zh
在浏览器中开始使用:
pdf2zh -i
如果您的浏览器没有自动启动,请访问
http://localhost:7860/
有关更多详细信息,请参阅 GUI 文档。
4. Docker
拉取并运行:
docker pull byaidu/pdf2zh docker run -d -p 7860:7860 byaidu/pdf2zh
在浏览器中打开:
http://localhost:7860/
对于云服务上的docker部署:
5. Zotero 插件
有关更多细节,请参见 [Zotero PDF2zh](https://github.com/guaguastandup/zotero-pdf2zh)。6. 命令行
已安装Python(3.10 <= 版本 <= 3.12)
安装我们的包:
pip install pdf2zh
执行翻译,文件生成在 当前工作目录:
pdf2zh document.pdf
如果你使用Windows并在下载后无法打开文件,请安装 vc_redist.x64.exe 并重试。
如果你无法访问Docker Hub,请尝试在 GitHub容器注册中心 上使用该镜像。
docker pull ghcr.io/byaidu/pdfmathtranslate docker run -d -p 7860:7860 ghcr.io/byaidu/pdfmathtranslate
无法安装?
当前程序在工作前需要一个AI模型(wybxc/DocLayout-YOLO-DocStructBench-onnx
),一些用户由于网络问题无法下载。如果你在下载此模型时遇到问题,我们提供以下环境变量的解决方法:
set HF_ENDPOINT=https://hf-mirror.com
对于 PowerShell 用户:
$env:HF_ENDPOINT = https://hf-mirror.com
如果此解决方案对您无效或您遇到其他问题,请参阅 常见问题解答。
高级选项
在命令行中执行翻译命令,在当前工作目录下生成译文文档 example-mono.pdf
和双语对照文档 example-dual.pdf
,默认使用 Google 翻译服务,更多支持的服务在这里)。

在下表中,我们列出了所有高级选项供参考:
选项 | 功能 | 示例 |
---|---|---|
files | 本地文件 | pdf2zh ~/local.pdf |
links | 在线文件 | pdf2zh http://arxiv.org/paper.pdf |
-i |
进入 GUI | pdf2zh -i |
-p |
部分文档翻译 | pdf2zh example.pdf -p 1 |
-li |
源语言 | pdf2zh example.pdf -li en |
-lo |
目标语言 | pdf2zh example.pdf -lo zh |
-s |
翻译服务 | pdf2zh example.pdf -s deepl |
-t |
多线程 | pdf2zh example.pdf -t 1 |
-o |
输出目录 | pdf2zh example.pdf -o output |
-f , -c |
异常 | pdf2zh example.pdf -f "(MS.*)" |
-cp |
兼容模式 | pdf2zh example.pdf --compatible |
--share |
公开链接 | pdf2zh -i --share |
--authorized |
授权 | pdf2zh -i --authorized users.txt [auth.html] |
--prompt |
自定义提示 | pdf2zh --prompt [prompt.txt] |
--onnx |
[使用自定义 DocLayout-YOLO ONNX 模型] | pdf2zh --onnx [onnx/model/path] |
--serverport |
[使用自定义 WebUI 端口] | pdf2zh --serverport 7860 |
--dir |
[批量翻译] | pdf2zh --dir /path/to/translate/ |
--config |
配置文件 | pdf2zh --config /path/to/config/config.json |
--serverport |
[自定义 gradio 服务器端口] | pdf2zh --serverport 7860 |
有关详细说明,请参阅我们的文档 高级用法,以获取每个选项的完整列表。
二次开发 (API)
对于下游应用程序,请参阅我们的文档 API 详细信息,以获取更多信息:
- Python API,如何在其他 Python 程序中使用该程序
- HTTP API,如何与已安装该程序的服务器进行通信
待办事项
修复页面旋转、目录、列表格式
修复旧论文中的像素公式
异步重试,除了 KeyboardInterrupt
针对西方语言的 Knuth–Plass 算法
支持非 PDF/A 文件
致谢
Immersive Translation 为此项目的活跃贡献者提供每月的专业会员兑换码,详细信息请查看:CONTRIBUTOR_REWARD.md
文档合并:PyMuPDF
文档解析:Pdfminer.six
文档提取:MinerU
文档预览:Gradio PDF
多线程翻译:MathTranslate
布局解析:DocLayout-YOLO
多语言字体:Go Noto Universal