Files
pdf-translator/README.md
coder 0384403c4c 初始提交: 英文PDF翻译中文工具
功能:
- 从PDF提取文本并翻译成中文
- 支持Markdown/TXT/JSON输出格式
- 上下文连贯翻译
- 自动重试机制

配置:
- API: http://192.168.2.5:1234/v1
- 模型: qwen/qwen3.5-35b-a3b
2026-04-07 18:27:43 +08:00

87 lines
2.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 英文PDF翻译中文工具
基于本地 LLM 服务Qwen3.5的英文PDF自动翻译工具。
## 功能特点
- ✅ 从 PDF 提取文本并翻译成中文
- ✅ 保持原文段落结构
- ✅ 支持多种输出格式 (Markdown/TXT/JSON)
- ✅ 上下文连贯翻译
- ✅ 自动重试机制
## 快速使用
```bash
# 翻译 PDF 为 Markdown
python translate_pdf.py input.pdf output.md
# 指定输出格式
python translate_pdf.py input.pdf output.txt --format txt
# JSON 格式(包含原文对照)
python translate_pdf.py input.pdf output.json --format json
# 测试 LLM 连接
python translate_pdf.py --test
```
## 配置说明
修改 `translate_pdf.py` 中的 `CONFIG` 部分:
```python
CONFIG = {
"api_base": "http://192.168.2.5:1234/v1", # LLM API 地址
"api_key": "sk-lm-fuP5tGU8:Hi7YU87jHyDP6Ay8Tl2j", # API Key
"model": "qwen/qwen3.5-35b-a3b", # 模型名称
"chunk_size": 2000, # 每次翻译字符数
"max_tokens": 8000, # 最大输出 token需足够让思考完成
"timeout": 180, # 单次请求超时(秒)
}
```
## 依赖安装
```bash
pip install pypdf openai
```
## 注意事项
⚠️ **Qwen 模型的思考模式**
Qwen3.5 模型会在翻译前进行"思考",占用大量 token。因此
- `max_tokens` 需设置较大(建议 8000+
- 翻译速度较慢(约 30秒/块)
- 适合处理重要文档,不适合快速预览
## 输出示例
输入英文:
```
Machine learning is a subset of artificial intelligence (AI)
that enables systems to learn and improve from experience.
```
输出中文:
```
机器学习是人工智能AI的一个子集
它使系统能够从经验中学习和改进。
```
## 文件结构
```
pdf-translator/
├── translate_pdf.py # 主翻译脚本
├── README.md # 使用说明
└── output.md # 翻译输出示例
```
## 扩展建议
1. **批量翻译**:循环处理多个 PDF
2. **进度保存**:中断后可从上次位置继续
3. **质量检查**:对比原文与译文段落
4. **格式优化**:保留 PDF 原排版样式