A simple yet powerful tool to translate English PDFs into fluent Chinese using the ChatGLM (GLM-4.5-Air) model.
- High-Quality Translation: Uses ZhipuAI's GLM-4.5-Air model for idiomatic translations.
- Context Preservation: Maintains the original paragraph structure.
- Bilingual Output: Generates a Markdown file with both original English text and Chinese translation side-by-side.
- Batch Processing: Optimizes API calls by batching text chunks for faster processing.
- Python 3.8 or higher
- A ZhipuAI API Key (Get one at open.bigmodel.cn)
-
Clone the repository (or download the files):
git clone <your-repo-url> cd PDF-Translate
-
Create and activate a virtual environment (recommended):
python -m venv venv # Windows .\venv\Scripts\activate # Linux/Mac source venv/bin/activate
-
Install dependencies:
pip install pymupdf zhipuai python-dotenv
-
Configure Environment: Create a
.envfile in the root directory and add your API key:API_KEY=your_zhipuai_api_key_here MODEL_NAME=GLM-4.5-Air
Run the script with the path to your PDF file:
python translate_pdf.py "path/to/your/document.pdf"python translate_pdf.py "sample-data/paper.pdf"The tool will generate a Markdown file in the same directory as the input PDF, with _translated.md appended to the filename.
Example Output (paper_translated.md):
# Translation of paper.pdf
## Page 1
### Original
This is the abstract of the paper.
### Translation
这是论文的摘要。
---Apache-2.0 license