English | 简体中文 | 繁體中文 | 日本語 | 한국어
<img src="./docs/images/banner.png" width="320px" alt="PDF2ZH"/> <h2 id="title">PDFMathTranslate</h2> <p> <!-- PyPI --> <a href="https://pypi.org/project/pdf2zh/"> <img src="https://img.shields.io/pypi/v/pdf2zh"></a> <a href="https://pepy.tech/projects/pdf2zh"> <img src="https://static.pepy.tech/badge/pdf2zh"></a> <a href="https://hub.docker.com/r/byaidu/pdf2zh"> <img src="https://img.shields.io/docker/pulls/byaidu/pdf2zh"></a> <a href="https://hellogithub.com/repository/8ec2cfd3ef744762bf531232fa32bc47" target="_blank"><img src="https://api.hellogithub.com/v1/widgets/recommend.svg?rid=8ec2cfd3ef744762bf531232fa32bc47&claim_uid=JQ0yfeBNjaTuqDU&theme=small" alt="推荐|HelloGitHub" /></a> <a href="https://gitcode.com/Byaidu/PDFMathTranslate/overview"> <img src="https://gitcode.com/Byaidu/PDFMathTranslate/star/badge.svg"></a> <a href="https://huggingface.co/spaces/reycn/PDFMathTranslate-Docker"> <img src="https://img.shields.io/badge/%F0%9F%A4%97-在线演示-FF9E0D"></a> <a href="https://www.modelscope.cn/studios/AI-ModelScope/PDFMathTranslate"> <img src="https://img.shields.io/badge/ModelScope-演示-blue"></a> <a href="https://github.com/Byaidu/PDFMathTranslate/pulls"> <img src="https://img.shields.io/badge/贡献欢迎-green"></a> <a href="https://t.me/+Z9_SgnxmsmA5NzBl"> <img src="https://img.shields.io/badge/Telegram-2CA5E0?style=flat-squeare&logo=telegram&logoColor=white"></a> <!-- License --> <a href="./LICENSE"> <img src="https://img.shields.io/github/license/Byaidu/PDFMathTranslate"></a> </p><a href="https://trendshift.io/repositories/12424" target="_blank"><img src="https://trendshift.io/api/badge/repositories/12424" alt="Byaidu%2FPDFMathTranslate | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
</div> <h2 id="updates">1. 这个工具做什么?</h2>科学PDF文档翻译,保留布局。
<div align="center"> <img src="./docs/images/preview.gif" width="80%"/> </div> <h2 id="updates">2. 最近更新</h2>[2025年5月9日] pdf2zh 2.0 预览版 #586:Windows ZIP 文件和 Docker 镜像现已可用。
[!NOTE]
2.0 已迁移到组织下的新仓库:PDFMathTranslate/PDFMathTranslate-next
正式发布版已发布。
[2025年2月22日] 更好的发布CI和打包良好的windows-amd64 exe(由@awwaawwa提供)
您可以尝试以下任一演示来使用我们的应用程序:
请注意,演示计算资源有限,请避免滥用它们。
<h3 id="install">3.2 本地安装</h3>针对不同的使用场景,我们提供了不同的使用方法:
<details open> <summary>3.2.1 Python: 使用uv安装</summary>安装Python(3.10 <= 版本 <= 3.12)
安装我们的包:
pip install uv
uv tool install --python 3.12 pdf2zh
执行翻译,生成的文件位于当前工作目录:
pdf2zh document.pdf
安装Python(3.10 <= 版本 <= 3.12)
安装我们的包:
pip install pdf2zh
执行翻译,生成的文件位于当前工作目录:
pdf2zh document.pdf
安装Python(3.10 <= 版本 <= 3.12)
安装我们的包:
pip install pdf2zh
在浏览器中开始使用:
pdf2zh -i
如果您的浏览器没有自动启动,请访问
http://localhost:7860/
<img src="./docs/images/gui.gif" width="500"/>
更多关于GUI的文档,请参阅GUI文档。
</details> <details> <summary>3.2.4 应用程序: 在Windows上</summary>从发行页面下载pdf2zh-version-win64.zip
解压并双击pdf2zh.exe运行。
</details> <details> <summary>3.2.5 参考管理器: Zotero插件</summary>[!TIP]
- 如果您使用的是Windows,并且下载后无法打开文件,请安装vc_redist.x64.exe并再次尝试。
更多详情,请参阅Zotero PDF2zh。
</details> <details> <summary>3.2.6 Docker: 容器化部署</summary>拉取并运行:
docker pull byaidu/pdf2zh
docker run -d -p 7860:7860 byaidu/pdf2zh
在浏览器中打开:
http://localhost:7860/
对于云服务上的Docker部署:
<div> <a href="https://www.heroku.com/deploy?template=https://github.com/Byaidu/PDFMathTranslate"> <img src="https://www.herokucdn.com/deploy/button.svg" alt="部署" height="26"></a> <a href="https://render.com/deploy"> <img src="https://render.com/images/deploy-to-render-button.svg" alt="部署到Koyeb" height="26"></a> <a href="https://zeabur.com/templates/5FQIGX?referralCode=reycn"> <img src="https://zeabur.com/button.svg" alt="在Zeabur上部署" height="26"></a> <a href="https://template.sealos.io/deploy?templateName=pdf2zh"> <img src="https://sealos.io/Deploy-on-Sealos.svg" alt="在Sealos上部署" height="26"></a> <a href="https://app.koyeb.com/deploy?type=git&builder=buildpack&repository=github.com/Byaidu/PDFMathTranslate&branch=main&name=pdf-math-translate"> <img src="https://www.koyeb.com/static/images/deploy/button.svg" alt="部署到Koyeb" height="26"></a> </div></details> <details> <summary>3.2.* 安装时网络问题解决方案</summary>[!TIP]
- 如果您无法访问Docker Hub,请尝试GitHub容器注册表中的镜像。
docker pull ghcr.io/byaidu/pdfmathtranslate docker run -d -p 7860:7860 ghcr.io/byaidu/pdfmathtranslate
特定地区的用户在加载AI模型时可能会遇到网络困难。当前程序依赖于AI模型(wybxc/DocLayout-YOLO-DocStructBench-onnx),由于这些网络问题,一些用户无法下载该模型。
为了解决下载此模型的问题,可以使用以下环境变量作为解决办法:
set HF_ENDPOINT=https://hf-mirror.com
对于PowerShell用户:
$env:HF_ENDPOINT = https://hf-mirror.com
如果上述解决方案对您无效或您遇到了其他问题,请参考常见问题解答。
</details> <h2 id="usage">4. 技术细节</h2>在命令行中执行翻译命令,在当前工作目录生成翻译后的文档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 |
--skip-subset-fonts | 跳过字体子集 | pdf2zh example.pdf --skip-subset-fonts |
--ignore-cache | 忽略翻译缓存 | pdf2zh example.pdf --ignore-cache |
--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 27017 |
--babeldoc | 使用实验后端BabelDOC进行翻译 | pdf2zh --babeldoc -s openai example.pdf |
--mcp | 启用MCP STDIO模式 | pdf2zh --mcp |
--sse | 启用MCP SSE模式 | pdf2zh --mcp --sse |
有关每个选项的详细解释,请参阅我们的高级用法文档。
<h3 id="downstream">4.2 下游开发</h3> 对于下游应用,请参阅我们的[API详情](./docs/APIS.md)文档以获取更多信息:Byaidu/PDFMathTranslate:当前和原始项目,用于稳定发布。
PDFMathTranslate/PDFMathTranslate-next:一个带有web-ui和额外功能的分支。这个分支处理了大量的边缘情况,提高了PDF兼容性,优化了跨栏和跨页的语义一致性、动态缩放和动态缩放一致性,以及其他许多翻译质量改进。然而,这个分支仅用于开发,不解决兼容性问题,也不适合社区贡献。