cd /news/artificial-intelligence/pdf-batch-translator · home topics artificial-intelligence article
[ARTICLE · art-60115] src=github.com ↗ pub= topic=artificial-intelligence verified=true sentiment=· neutral

PDF Batch Translator

A developer released PDF Batch Translator, an open-source CLI tool that batch-translates English PDFs into Japanese Markdown while preserving structure and stripping non-body content. The tool uses Anthropic's Claude models and maintains translation consistency across document chunks by passing context from prior segments.

read3 min views1 publishedJul 15, 2026
PDF Batch Translator
Image: source

Batch-translate English PDFs into Japanese Markdown — body text only, structure preserved.

英文PDFを一括で放り込むと、本文だけを逐語訳して .md

で出力する CLI ツール。

📝

Background & design notes / 解説記事:[Building an AI PDF translation tool]

Point it at a folder of English PDFs and it translates each one to Japanese, writing <folder>/jp-translations/<name>.md

. Three things make it more than a folder loop over an API call:

Body text only. Navigation, search boxes, ads, prev/next links, page numbers, headers/footers, "Downloaded from…" lines, footnotes/endnotes, bibliographies, and image credits are stripped. Lines that repeat across pages are removed mechanically; the final body-vs-furniture judgment is left to the model.Literal, structure-preserving. Translates faithfully (直訳) — word order, paragraphs, and headings are kept as Markdown — instead of loosely paraphrasing.Context carried across chunks. The tail of the previous translation is passed back in on every call, so terminology and sentence flow stay consistent across chapters instead of each chunk being translated in isolation.

It also writes output atomically after every chunk, so Ctrl+C

never leaves a corrupted file — the translation so far is safely on disk.

  • Python 3.9+
  • An Anthropic API key pip install -r requirements.txt

(PyMuPDF, anthropic, python-dotenv)

cd pdf-batch-translator
python3 -m venv .venv
source .venv/bin/activate          # Windows: .venv\Scripts\activate
pip install -r requirements.txt

export ANTHROPIC_API_KEY=sk-...     # or put it in a .env file (see below)

python translate_pdfs.py /path/to/folder

python translate_pdfs.py --file sample.pdf --out result.md

The API key can come from an environment variable or a .env

file placed next to the script (or in the directory you run it from):

ANTHROPIC_API_KEY=sk-...
Option Default Description
--file / -f
Translate a single PDF (single-file / test mode)
--out / -o
Output .md for single-file mode; defaults to <name>.md beside the source
--model
claude-sonnet-4-6
Model to use; bump to claude-opus-4-8 etc. for higher quality
--chunk-chars
3500
Max source characters per API call
--context-chars
1200
Trailing chars of prior translation passed as context
--glossary
Glossary file, one source = 訳語 pair per line
--max-chunk
10
Max chunks translated per file (safety cap); excess is skipped
--no-max-chunk
off Remove the chunk cap and translate the whole file
--overwrite
off Re-translate even if an output .md already exists (batch mode)
cd pdf-batch-translator
python3 -m venv .venv
source .venv/bin/activate          # Windows: .venv\Scripts\activate
pip install -r requirements.txt

APIキーは環境変数か .env

のどちらでも可。.env

を使う場合はスクリプトと 同じ場所(またはコマンドを実行するカレントディレクトリ)に置く:

ANTHROPIC_API_KEY=sk-...

環境変数で渡す場合:

export ANTHROPIC_API_KEY=sk-...   # Windows(PowerShell): $env:ANTHROPIC_API_KEY="sk-..."

フォルダ一括モード

python translate_pdfs.py /path/to/フォルダ

/path/to/フォルダ

内の *.pdf

を順に処理し、 /path/to/フォルダ/jp-translations/<元ファイル名>.md

に書き出す。

単一ファイルモード(テスト向け)

python translate_pdfs.py --file sample.pdf --out result.md

--out

を省略すると、元PDFと同じ場所に <元ファイル名>.md

を作成する。

Bank of England = イングランド銀行
Committee of Inspection = 監査委員会
clerk = 書記

本文のみ:ナビゲーション/検索ボックス/広告/前後リンク/ページ番号/ヘッダ・フッタ/ ダウンロード表示/脚注・尾注/参考文献一覧/画像クレジットは訳出しない。 ページをまたいで繰り返す行は機械的に除去し、最終的な本文判定はモデルが行う。逐語訳:意訳しない。段落・見出し構造は保持。流れの考慮:直前までの訳文の末尾を毎回モデルに渡すので、章をまたいでも 訳語と文の流れが一貫する(単純に逐次投げるだけ、にしていない)。

  • 出力ファイルが 存在しなければ翻訳し、存在すれば翻訳しない。 つまり、まだ訳していないファイルだけが処理される。 - やり直したいときは、 その出力ファイルを削除してから再実行する。 削除すれば次回の実行でそのファイルだけが翻訳される。

  • 訳はチャンクごとに .md

へ上書き保存される。Ctrl+C

で止めても、 直前のチャンクまでの訳が.md

に残る(書き込みはアトミックなので壊れない)。 - ただし、その .md

は「存在する」ため、そのまま再実行してもスキップされ、 続きは翻訳されない。続きを訳すには、当該ファイルを削除してから再実行する。

  • 既定では 1 ファイルあたり 10 チャンクまでしか翻訳しない(--max-chunk 10

)。 巨大な PDF で API を使いすぎないための安全弁。 - 上限が適用されたファイルは、出力名が <名前>.upto10chunk.md

になり、 訳文末尾に「上限が適用されたこと」と「解除方法」の注記が付く。 全文を翻訳するには、その.upto10chunk.md

を削除してから、- より大きい値を指定: --max-chunk 50

など、または - 上限を解除: --no-max-chunk

を付けて再実行する。

  • より大きい値を指定:
── more in #artificial-intelligence 4 stories · sorted by recency
── more on @anthropic 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/pdf-batch-translator] indexed:0 read:3min 2026-07-15 ·