GitHub - markmatsu/pdf-batch-translator: Translate a folder of English PDFs into Japanese Markdown, body text only. · GitHub
/" data-turbo-transient="true" />
Skip to content
Search or jump to...
Search code, repositories, users, issues, pull requests...
-->
Search
Clear
Search syntax tips
Provide feedback
--><br>We read every piece of feedback, and take your input very seriously.
Include my email address so I can be contacted
Cancel
Submit feedback
Saved searches
Use saved searches to filter your results more quickly
-->
Name
Query
To see all available qualifiers, see our documentation.
Cancel
Create saved search
Sign in
/;ref_cta:Sign up;ref_loc:header logged out"}"<br>Sign up
Appearance settings
Resetting focus
You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
{{ message }}
markmatsu
pdf-batch-translator
Public
Notifications<br>You must be signed in to change notification settings
Fork
Star
main
BranchesTags
Go to file
CodeOpen more actions menu
Folders and files<br>NameNameLast commit message<br>Last commit date<br>Latest commit
History<br>2 Commits<br>2 Commits
.gitignore
.gitignore
LICENSE
LICENSE
README.md
README.md
requirements.txt
requirements.txt
translate_pdfs.py
translate_pdfs.py
View all files
Repository files navigation
PDF Batch Translator / 英文PDF一括翻訳ツール
Batch-translate English PDFs into Japanese Markdown — body text only , structure preserved.
英文PDFを一括で放り込むと、本文だけ を逐語訳して .md で出力する CLI ツール。
📝 Background & design notes / 解説記事:<br>Building an AI PDF translation tool
What it does
Point it at a folder of English PDFs and it translates each one to Japanese, writing<br>/jp-translations/.md. Three things make it more than a folder loop over an<br>API call:
Body text only. Navigation, search boxes, ads, prev/next links, page numbers,<br>headers/footers, "Downloaded from…" lines, footnotes/endnotes, bibliographies, and<br>image credits are stripped. Lines that repeat across pages are removed mechanically;<br>the final body-vs-furniture judgment is left to the model.
Literal, structure-preserving. Translates faithfully (直訳) — word order, paragraphs,<br>and headings are kept as Markdown — instead of loosely paraphrasing.
Context carried across chunks. The tail of the previous translation is passed back in<br>on every call, so terminology and sentence flow stay consistent across chapters instead<br>of each chunk being translated in isolation.
It also writes output atomically after every chunk , so Ctrl+C never leaves a corrupted<br>file — the translation so far is safely on disk.
Requirements
Python 3.9+
An Anthropic API key
pip install -r requirements.txt (PyMuPDF, anthropic, python-dotenv)
Quick start
cd pdf-batch-translator<br>python3 -m venv .venv<br>source .venv/bin/activate # Windows: .venv\Scripts\activate<br>pip install -r requirements.txt
export ANTHROPIC_API_KEY=sk-... # or put it in a .env file (see below)
# batch: translate every PDF in a folder<br>python translate_pdfs.py /path/to/folder
# single file (handy for testing)<br>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<br>script (or in the directory you run it from):
# .env<br>ANTHROPIC_API_KEY=sk-...
Options
Option<br>Default<br>Description
--file / -f<br>Translate a single PDF (single-file / test mode)
--out / -o<br>Output .md for single-file mode; defaults to .md beside the source
--model<br>claude-sonnet-4-6<br>Model to use; bump to claude-opus-4-8 etc. for higher quality
--chunk-chars<br>3500<br>Max source characters per API call
--context-chars<br>1200<br>Trailing chars of prior translation passed as context
--glossary<br>Glossary file, one source = 訳語 pair per line
--max-chunk<br>10<br>Max chunks translated per file (safety cap); excess is skipped
--no-max-chunk<br>off<br>Remove the chunk cap and translate the whole file
--overwrite<br>off<br>Re-translate even if an output .md already exists (batch mode)
日本語ドキュメント
セットアップ(venv)
cd pdf-batch-translator<br>python3 -m venv .venv<br>source .venv/bin/activate # Windows: .venv\Scripts\activate<br>pip install -r requirements.txt
APIキーは環境変数か .env のどちらでも可。.env を使う場合はスクリプトと<br>同じ場所(またはコマンドを実行するカレントディレクトリ)に置く:
# .env<br>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 を順に処理し、<br>/path/to/フォルダ/jp-translations/.md に書き出す。
単一ファイルモード(テスト向け)
python translate_pdfs.py --file sample.pdf --out result.md
--out を省略すると、元PDFと同じ場所に .md を作成する。
用語集の例(任意)
Bank of England = イングランド銀行<br>Committee of Inspection = 監査委員会<br>clerk = 書記
動作の要点
本文のみ :ナビゲーション/検索ボックス/広告/前後リンク/ページ番号/ヘッダ・フッタ/<br>ダウンロード表示/脚注・尾注/参考文献一覧/画像クレジットは訳出しない。<br>ページをまたいで繰り返す行は機械的に除去し、最終的な本文判定はモデルが行う。
逐語訳 :意訳しない。段落・見出し構造は保持。
流れの考慮...