PDFMathTranslate (pdf2zh) translates PDF documents while keeping formulas, charts, the table of contents and annotations in place, and it can send the text to a model running in Ollama on your own PC instead of an online service. This guide covers the original 1.x version, which has a built-in Ollama option.
What you need
Python 3.11 or 3.12. PDFMathTranslate's README asks for a version between 3.11 and 3.12.
Ollama installed and running, with a model downloaded. If you haven't set it up yet, see our guide to running AI models locally.
A PDF with selectable text. Scanned pages need the optional OCR extra covered below.
Step 1: Download a model in Ollama
Open a terminal and pull a model with ollama pull, for example:
ollama pull gemma4
Ollama's CLI documentation uses ollama ls to list the models you have and ollama serve to start Ollama if it isn't already running. Note the exact model name, as you'll need it in Step 3. For help choosing one, see our best local LLM models.
Step 2: Install PDFMathTranslate
The project suggests installing with uv:
pip install uv
uv tool install --python 3.12 pdf2zh
Alternatively, run pip install pdf2zh. On Windows there's also a pdf2zh ZIP on the release page; unzip it and double-click pdf2zh.exe. If it won't open, the project says to install Microsoft's vc_redist.x64.exe and try again.
Step 3: Point it at Ollama
PDFMathTranslate's ollama service reads two environment variables: OLLAMA_HOST, which defaults to http://127.0.0.1:11434, and OLLAMA_MODEL. In Windows Command Prompt:
set OLLAMA_HOST=http://127.0.0.1:11434
set OLLAMA_MODEL=gemma4
In PowerShell, use $env:OLLAMA_MODEL = "gemma4" instead. Our guide to setting Ollama environment variables on Windows covers Ollama's own settings.
Step 4: Translate the PDF
Run the command from the folder you want the output in, choosing the source language with -li, the target language with -lo and the service with -s:
pdf2zh document.pdf -li en -lo fr -s ollama
Always include -s ollama. PDFMathTranslate uses Google as its default translation service, so leaving it out would send your text online. The tool creates two files in the current working directory: a translated document-mono.pdf and a bilingual document-dual.pdf. Use -o to choose a different output folder.
Useful options
Translate only some pages: -p 1-3,5.
Threads: -t sets how many translation threads to use, for example -t 1.
Whole folders: --dir /path/to/translate/ batch-translates a directory.
Custom prompt: --prompt prompt.txt changes the instructions sent to the LLM.
Native-text PDFs: after pip install 'pdf2zh[ultrafast]', the --ultrafast mode uses the PDF's own text positions and skips the ONNX layout model and OCR. The project says it's best for PDFs that already contain text and recommends normal mode for complex tables or formulas.
Scanned pages: experimental OCR is available with pip install 'pdf2zh[ocr]'. It downloads Tesseract language data on first use and targets white-background scans; the project warns that handwriting and inline equations may be recognised incorrectly.
Prefer a browser interface?
Run pdf2zh -i and go to http://localhost:7860/ if your browser doesn't open on its own. If you'd rather use the newer PDFMathTranslate 2.0, see our best local AI PDF translators and our PDFMathTranslate vs BabelDOC comparison.
Troubleshooting
Model download fails on first run: PDFMathTranslate needs a layout model (DocLayout-YOLO) from Hugging Face. The README suggests setting the HF_ENDPOINT mirror variable if your network blocks the download.
Ollama not found: make sure Ollama is running and that OLLAMA_HOST matches its address. Our Ollama OpenAI API guide explains how its local server works.