A professional PDF translation tool based on PDFMathTranslate-next and BabelDOC that converts PDF documents to bilingual (dual-language) versions while preserving original formatting including formulas, tables, and graphics.
- Format Preservation: Maintains original layout, formulas, tables, and graphics
- Bilingual Output: Generates both dual-language (bilingual) and single-language (translation only) PDFs
- Multiple Translation Engines: Supports various translation providers including ZhipuAI, VolcEngine, SiliconFlow, and OpenAI
- Term Extraction: Automatically extracts and generates glossary files
- Batch Processing: Supports batch translation of multiple PDF files
- Customizable: Supports custom system prompts and translation parameters
- Page Range Selection: Translate specific pages or ranges
- High Performance: Configurable QPS (queries per second) for faster translation
# Clone the repository
git clone https://github.com/boyingliu01/pdf-translation.git
cd pdf-translation
# Install dependencies
pip install -r requirements.txtCopy and edit a configuration template based on your preferred translation provider:
# Using ZhipuAI (recommended, free tier available)
cp config/config.zhipu.json config/config.json
# Edit config/config.json and replace "your-zhipuai-api-key-here" with your actual API key
# Using VolcEngine
cp config/config.volcengine.json config/config.json
# Edit config/config.json and replace "your-volcengine-api-key-here" with your actual API key
# Using SiliconFlow
cp config/config.siliconflow.json config/config.json
# Edit config/config.json and replace "your-siliconflow-api-key-here" with your actual API key
# Using OpenAI
cp config/config.openai.json config/config.json
# Edit config/config.json and replace "your-api-key-here" with your actual API keyAPI Key Registration:
- ZhipuAI: https://open.bigmodel.cn/ - Free tier available, recommended
- VolcEngine: https://console.volcengine.com/ark - Requires subscription
- SiliconFlow: https://siliconflow.cn/ - Various models available
- OpenAI: https://platform.openai.com/ - Pay-as-you-go
# Basic translation
python translate_pdf.py -i path/to/document.pdf -o path/to/output
# With language specification
python translate_pdf.py -i document.pdf -o output --lang-in en --lang-out zh
# Specific pages only
python translate_pdf.py -i document.pdf -o output --pages "1-5"
# Without dual-language output
python translate_pdf.py -i document.pdf -o output --no-dual| Argument | Short | Description | Default |
|---|---|---|---|
--input |
-i |
Input PDF file path (required) | - |
--output |
-o |
Output directory | PDF parent directory |
--config |
-c |
Configuration file path | config/config.json |
--lang-in |
-li |
Source language code | en |
--lang-out |
-lo |
Target language code | zh |
--no-dual |
- | Skip dual-language PDF output | false |
--no-mono |
- | Skip single-language PDF output | false |
--watermark |
- | Watermark mode: watermarked/no_watermark/both |
watermarked |
--pages |
- | Page range: 1,2,1-,-3,3-5 |
All pages |
--max-pages-per-part |
- | Max pages per batch for large documents | - |
--enhance-compatibility |
- | Enable compatibility enhancements | false |
--create-config |
- | Create example config file | - |
| Option | Description | Default |
|---|---|---|
translation_engine |
Translation engine type | openai |
openai_api_key |
API key for the translation service | - |
openai_base_url |
API base URL | - |
openai_model |
Model name | glm-4-flash (ZhipuAI) |
qps |
Queries per second (higher = faster) | 4 |
min_text_length |
Minimum text length for translation | 5 |
debug |
Enable debug mode | false |
custom_system_prompt |
Custom system prompt | null |
enable_term_extraction |
Enable term extraction/glossary | false |
page_markdown |
Enable page markdown | false |
Uses the GLM-4-Flash model from ZhipuAI. Offers a generous free tier with high translation quality.
Registration: https://open.bigmodel.cn/
Uses Doubao models from VolcEngine. Requires a subscription plan.
Registration: https://console.volcengine.com/ark
Supports various models including DeepSeek.
Registration: https://siliconflow.cn/
Uses native OpenAI models like GPT-4o-mini.
Registration: https://platform.openai.com/
Translation generates the following files:
<filename>.zh-CN.dual.pdf- Bilingual PDF (recommended)<filename>.zh-CN.mono.pdf- Single-language PDF (translation only)<filename>.zh-CN.dual.no-watermark.pdf- Unwatermarked dual (if watermark mode is set tobothorno_watermark)<filename>.zh-CN.mono.no-watermark.pdf- Unwatermarked mono (if watermark mode is set tobothorno_watermark)<filename>.zh-CN.glossary.csv- Glossary file (if term extraction enabled)
- Increase QPS: Set a higher
qpsvalue in the configuration file for faster translation - Use faster models: Models like
glm-4-flashordoubao-pro-4koffer good speed-quality balance - Batch processing: Use
--max-pages-per-partfor very large documents - Page range selection: Translate specific pages first to test quality before full translation
For more detailed information, see the docs/ directory:
- QUICKSTART.md - Quick start guide
- USAGE_GUIDE.md - Detailed usage guide
- ENGINES_GUIDE.md - Translation engine configuration guide
A: Increase the qps value in your configuration file, use a faster model (like glm-4-flash), or use the --max-pages-per-part option for batch processing.
A: Use a higher-quality model (like gpt-4o), add a custom system prompt, or enable term extraction to provide context.
A: The tool supports translation between all major language pairs, including Chinese-English, English-Japanese, English-French, and more.
A: Yes, as long as your API is OpenAI-compatible, you can configure it by setting the appropriate openai_base_url and openai_model in the configuration file.
Contributions are welcome! Please feel free to submit issues or pull requests.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
This project is built upon:
- PDFMathTranslate-next - Core translation library
- BabelDOC - PDF parsing and layout analysis
For questions or support, please open an issue on GitHub.