Skip to content

qingyangAI/PDF-Translate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PDF Translate

A simple yet powerful tool to translate English PDFs into fluent Chinese using the ChatGLM (GLM-4.5-Air) model.

Features

  • 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.

Prerequisites

Installation

  1. Clone the repository (or download the files):

    git clone <your-repo-url>
    cd PDF-Translate
  2. Create and activate a virtual environment (recommended):

    python -m venv venv
    # Windows
    .\venv\Scripts\activate
    # Linux/Mac
    source venv/bin/activate
  3. Install dependencies:

    pip install pymupdf zhipuai python-dotenv
  4. Configure Environment: Create a .env file in the root directory and add your API key:

    API_KEY=your_zhipuai_api_key_here
    MODEL_NAME=GLM-4.5-Air

Usage

Run the script with the path to your PDF file:

python translate_pdf.py "path/to/your/document.pdf"

Example

python translate_pdf.py "sample-data/paper.pdf"

Output

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
这是论文的摘要。

---

License

Apache-2.0 license

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages