Skip to content

How-ToGPU

How to Translate PDFs Locally with PDFMathTranslate and Ollama

PDFMathTranslate (pdf2zh) can translate a PDF while keeping formulas, charts and layout, using a model running in Ollama on your own PC. Here's how to install it, connect it to Ollama, pick languages and pages, and avoid accidentally using its default online service.

By , Systems & Technical Editor

3 min read

How to Translate PDFs Locally with PDFMathTranslate and Ollama

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.

The bottom line

Install pdf2zh with uv or pip, pull a model in Ollama, set OLLAMA_HOST and OLLAMA_MODEL, then run pdf2zh with -s ollama and your chosen languages. You'll get a translated PDF and a side-by-side bilingual PDF with the layout kept. Never skip the -s option, because the default service is Google rather than your local model.

Sources

  1. 01PDFMathTranslate on GitHub (1.x README)
  2. 02PDFMathTranslate 1.x: Advanced usage (docs/ADVANCED.md)
  3. 03Ollama docs: CLI reference

About the author

Marcus Thorne

Systems & Technical Editor

Marcus writes Forge PC's step-by-step build, troubleshooting and system optimisation guides. His background spans Windows kernel and power-state diagnostics, UEFI/BIOS configuration, NVMe storage arrays, ATX 3.1 power delivery and running local AI and LLM workloads on consumer graphics cards.

More from Marcus Thorne

Read next

How to Rename Your PC in Windows 11

How-To

How to Rename Your PC in Windows 11

Stuck with a random PC name like DESKTOP-something? We show how to check your current computer name and rename your PC in Windows 11 using Settings or PowerShell's Rename-Computer, following Microsoft's documentation, plus the naming rules that keep the new name working on your network.

Marcus Thorne3 min

The Best Steam Features Every PC Gamer Should Be Using in 2026

Best Picks

The Best Steam Features Every PC Gamer Should Be Using in 2026

Steam is much more than a shop and launcher. Using Valve's own support pages and documentation, we pick the best built-in Steam features for PC gamers, from Game Recording and the Performance Monitor to Steam Cloud, Steam Families, Remote Play, Big Picture mode, Steam Input and file verification.

Hannah Vance5 min

How to Customise the Lock Screen in Windows 11

How-To

How to Customise the Lock Screen in Windows 11

Windows 11's lock screen doesn't have to stay on the defaults. Following Microsoft's support guide, we show how to set Windows spotlight, a picture or a slideshow, turn off the tips and fun facts, show the same image on the sign-in screen, and add, reorder or hide lock screen widgets.

Marcus Thorne3 min

PDFMathTranslate vs BabelDOC: Which Local PDF Translator Should You Use?

Versus

PDFMathTranslate vs BabelDOC: Which Local PDF Translator Should You Use?

PDFMathTranslate and BabelDOC both translate PDFs while keeping layouts and can use local AI models through Ollama. Using their official docs, we compare how they're related, ease of use, local model support, output options and which one you should install.

Callum Reid3 min