{"slug": "pdf-batch-translator", "title": "PDF Batch Translator", "summary": "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.", "body_md": "Batch-translate English PDFs into Japanese Markdown — **body text only**, structure preserved.\n\n英文PDFを一括で放り込むと、**本文だけ**を逐語訳して `.md`\n\nで出力する CLI ツール。\n\n📝\n\nBackground & design notes / 解説記事:[Building an AI PDF translation tool]\n\nPoint it at a folder of English PDFs and it translates each one to Japanese, writing\n`<folder>/jp-translations/<name>.md`\n\n. Three things make it more than a folder loop over an\nAPI call:\n\n**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.\n\nIt also writes output **atomically after every chunk**, so `Ctrl+C`\n\nnever leaves a corrupted\nfile — the translation so far is safely on disk.\n\n- Python 3.9+\n- An Anthropic API key\n`pip install -r requirements.txt`\n\n(PyMuPDF, anthropic, python-dotenv)\n\n```\ncd pdf-batch-translator\npython3 -m venv .venv\nsource .venv/bin/activate          # Windows: .venv\\Scripts\\activate\npip install -r requirements.txt\n\nexport ANTHROPIC_API_KEY=sk-...     # or put it in a .env file (see below)\n\n# batch: translate every PDF in a folder\npython translate_pdfs.py /path/to/folder\n\n# single file (handy for testing)\npython translate_pdfs.py --file sample.pdf --out result.md\n```\n\nThe API key can come from an environment variable **or** a `.env`\n\nfile placed next to the\nscript (or in the directory you run it from):\n\n```\n# .env\nANTHROPIC_API_KEY=sk-...\n```\n\n| Option | Default | Description |\n|---|---|---|\n`--file` / `-f` |\n— | Translate a single PDF (single-file / test mode) |\n`--out` / `-o` |\n— | Output `.md` for single-file mode; defaults to `<name>.md` beside the source |\n`--model` |\n`claude-sonnet-4-6` |\nModel to use; bump to `claude-opus-4-8` etc. for higher quality |\n`--chunk-chars` |\n`3500` |\nMax source characters per API call |\n`--context-chars` |\n`1200` |\nTrailing chars of prior translation passed as context |\n`--glossary` |\n— | Glossary file, one `source = 訳語` pair per line |\n`--max-chunk` |\n`10` |\nMax chunks translated per file (safety cap); excess is skipped |\n`--no-max-chunk` |\noff | Remove the chunk cap and translate the whole file |\n`--overwrite` |\noff | Re-translate even if an output `.md` already exists (batch mode) |\n\n```\ncd pdf-batch-translator\npython3 -m venv .venv\nsource .venv/bin/activate          # Windows: .venv\\Scripts\\activate\npip install -r requirements.txt\n```\n\nAPIキーは環境変数か `.env`\n\nのどちらでも可。`.env`\n\nを使う場合はスクリプトと\n同じ場所(またはコマンドを実行するカレントディレクトリ)に置く:\n\n```\n# .env\nANTHROPIC_API_KEY=sk-...\n```\n\n環境変数で渡す場合:\n\n```\nexport ANTHROPIC_API_KEY=sk-...   # Windows(PowerShell): $env:ANTHROPIC_API_KEY=\"sk-...\"\n```\n\n**フォルダ一括モード**\n\n```\npython translate_pdfs.py /path/to/フォルダ\n```\n\n`/path/to/フォルダ`\n\n内の `*.pdf`\n\nを順に処理し、\n`/path/to/フォルダ/jp-translations/<元ファイル名>.md`\n\nに書き出す。\n\n**単一ファイルモード(テスト向け)**\n\n```\npython translate_pdfs.py --file sample.pdf --out result.md\n```\n\n`--out`\n\nを省略すると、元PDFと同じ場所に `<元ファイル名>.md`\n\nを作成する。\n\n```\nBank of England = イングランド銀行\nCommittee of Inspection = 監査委員会\nclerk = 書記\n```\n\n**本文のみ**:ナビゲーション/検索ボックス/広告/前後リンク/ページ番号/ヘッダ・フッタ/ ダウンロード表示/脚注・尾注/参考文献一覧/画像クレジットは訳出しない。 ページをまたいで繰り返す行は機械的に除去し、最終的な本文判定はモデルが行う。**逐語訳**:意訳しない。段落・見出し構造は保持。**流れの考慮**:直前までの訳文の末尾を毎回モデルに渡すので、章をまたいでも 訳語と文の流れが一貫する(単純に逐次投げるだけ、にしていない)。\n\n- 出力ファイルが\n**存在しなければ翻訳し、存在すれば翻訳しない**。 つまり、まだ訳していないファイルだけが処理される。 - やり直したいときは、\n**その出力ファイルを削除してから**再実行する。 削除すれば次回の実行でそのファイルだけが翻訳される。\n\n- 訳はチャンクごとに\n`.md`\n\nへ上書き保存される。`Ctrl+C`\n\nで止めても、 直前のチャンクまでの訳が`.md`\n\nに残る(書き込みはアトミックなので壊れない)。 - ただし、その\n`.md`\n\nは「存在する」ため、そのまま再実行してもスキップされ、 続きは翻訳されない。**続きを訳すには、当該ファイルを削除してから**再実行する。\n\n- 既定では 1 ファイルあたり\n**10 チャンクまで**しか翻訳しない(`--max-chunk 10`\n\n)。 巨大な PDF で API を使いすぎないための安全弁。 - 上限が適用されたファイルは、出力名が\n`<名前>.upto10chunk.md`\n\nになり、 訳文末尾に「上限が適用されたこと」と「解除方法」の注記が付く。 **全文を翻訳するには**、その`.upto10chunk.md`\n\nを削除してから、- より大きい値を指定:\n`--max-chunk 50`\n\nなど、または - 上限を解除:\n`--no-max-chunk`\n\nを付けて再実行する。\n\n- より大きい値を指定:", "url": "https://wpnews.pro/news/pdf-batch-translator", "canonical_source": "https://github.com/markmatsu/pdf-batch-translator", "published_at": "2026-07-15 07:15:03+00:00", "updated_at": "2026-07-15 07:48:10.464306+00:00", "lang": "en", "topics": ["artificial-intelligence", "large-language-models", "ai-tools", "developer-tools", "natural-language-processing"], "entities": ["Anthropic", "Claude", "PDF Batch Translator", "PyMuPDF", "python-dotenv"], "alternates": {"html": "https://wpnews.pro/news/pdf-batch-translator", "markdown": "https://wpnews.pro/news/pdf-batch-translator.md", "text": "https://wpnews.pro/news/pdf-batch-translator.txt", "jsonld": "https://wpnews.pro/news/pdf-batch-translator.jsonld"}}