pdf2zhをより便利に活用する
pdf2zhは、PDFのレイアウトを保持したまま翻訳を行うソフトウェア。ollamaを含む様々なLLMを翻訳に利用できる。 オリジナルと翻訳済みのページを左右に並べて表示するPDFも生成でき、その有用性は高い。

Terminalからの実行はちょっと手間なので、右クリックメニューから呼び出せるよう設定する。
Automatorを利用して右クリックから呼び出す
MacのAutomatorを使えば、シェルスクリプトを右クリックメニューから簡単に実行可能。


設定手順は以下の通り。
Automatorで「クイックアクション」を新規作成。
"Workflow receives current"を「PDFファイル」に指定し、「アプリケーション」を「Finder」に設定。
左メニューから「シェルスクリプトを実行」を選択。
右上の"Pass input"で"as arguments"を選択。
シェルスクリプトを記述。以下はGeminiとGemma3をOllamaで使用する例。
#!/bin/zsh PDF2ZH_PATH="$HOME/.local/bin/pdf2zh" notification(){ /usr/bin/osascript -e "display notification \"$@\" with title \"pdf2ja-gemini\"" } if [ -z "$@" ]; then notification The arguments are empty exit 1 fi # Load zshrc file which defines GEMINI_API_KEY if [ -e "$HOME/.zshrc.mine" ]; then source $HOME/.zshrc.mine fi if ! command -v ${PDF2ZH_PATH} &> /dev/null; then notifiaction Error: pdf2zh is not installed exit 1 fi if [ -z "${GEMINI_API_KEY}" ]; then notification Error: GEMINI_API_KEY is empty exit 1 fi for f in "$@" do notification "Translating: $f" "$PDF2ZH_PATH" -lo ja -li en -s gemini:gemini-2.5-flash "$f" --output $(dirname "$f") >>/tmp/pdf2zh.log 2>&1 if [ "$?" != "0" ]; then notification "Failed to convert $f" exit 1 fi notification "Done: $f" doneollamaを使うならこんな感じ。
#!/bin/zsh PDF2ZH_PATH="$HOME/.local/bin/pdf2zh" OLLAMA_MODEL="gemma3:4b" args="$@" notification(){ /usr/bin/osascript -e "display notification \"$@\" with title \"pdf2ja-gemma3\"" } if [ -z "$@" ]; then notification The arguments are empty exit 1 fi if ! command -v ${PDF2ZH_PATH} &> /dev/null; then notification Error: pdf2zh is not installed exit 1 fi if ! command -v ollama &> /dev/null; then notification Error: ollama is not installed. Please install ollama from ollama.com return 1 fi # Check if ollama is running if ! ollama ps &> /dev/null; then notification "Error: ollama server is not running. Please start ollama." return 1 fi for f in "$args" do notification "Translating: $f" "$PDF2ZH_PATH" -lo ja -li en -s ollama:"$OLLAMA_MODEL" --output $(dirname "$f") "$f" >>/tmp/pdf2zh.log 2>&1 if [ "$?" != "0" ]; then notification "Failed to convert $f" exit 1 fi notification "Done: $f" done


