PDF Viewer Translator
English
PDF Viewer Translator is a VS Code extension that opens PDF files, extracts page text, and translates it into a selected language. Translated text is rendered in a PDF-like page layout so the result stays visually close to the original document.
Features
- Open PDF files inside VS Code.
- Navigate pages and zoom in or out.
- Resize the PDF and translation panes by dragging the divider.
- Automatically translate the current page when the PDF opens or the page changes.
- Translate the current page or the whole document.
- Choose a target language from the toolbar.
- Choose
Fast, Balanced, or Accurate translation mode.
- Summarize the current page or the whole document.
- Page through translated pages independently from the original PDF.
- Display translated results in a page layout that follows the original PDF text positions.
Requirements
Translation uses the VS Code Language Model API. You need an available language model provider, such as GitHub Copilot Chat, and you may need to sign in or grant model access when prompted by VS Code.
Security
The extension restricts webview resource access to the PDF folder and bundled extension assets, uses a strict Content Security Policy, validates webview messages before model requests, and renders model output as text rather than raw HTML.
Usage
- Install the extension from VS Code Marketplace.
- Run
PDF Translator: Open PDF from the command palette, or open a .pdf file with PDF Viewer Translator.
- Select a target language.
- Click
Translate Page or Translate All.
Development
npm install
npm run compile
Open this folder in VS Code and press F5 to launch the Extension Development Host.
Project Structure
src/extension.ts: Extension entry point
src/pdfTranslatorProvider.ts: PDF custom editor and webview message handling
src/translator.ts: Translation through the VS Code Language Model API
src/webview.ts: Webview HTML generation
src/webview.js: PDF.js rendering, text extraction, and translated page layout
src/webview.css: Webview UI styles
日本語
PDF Viewer Translator は、VS Code 上で PDF を開き、ページ内のテキストを抽出して選択した言語へ翻訳する拡張機能です。翻訳結果は PDF 風のページレイアウトで表示されるため、元の文書に近い見た目で確認できます。
機能
- VS Code 内で PDF ファイルを表示
- ページ移動とズーム操作
- 境界線のドラッグによる PDF ペインと翻訳ペインの幅調整
- PDF を開いた時やページ変更時に現在ページを自動翻訳
- 現在ページまたはドキュメント全体の翻訳
- ツールバーから翻訳先言語を選択
Fast、Balanced、Accurate の翻訳モードを選択
- 現在ページまたはドキュメント全体の要約
- 元 PDF とは別に翻訳ページだけをページ送り
- 元 PDF のテキスト位置に沿ったページ風レイアウトで翻訳結果を表示
必要条件
翻訳には VS Code Language Model API を使います。GitHub Copilot Chat など、利用可能な言語モデルプロバイダーが必要です。VS Code から求められた場合は、サインインやモデル利用許可を行ってください。
セキュリティ
Webview からアクセスできるリソースは PDF のフォルダと拡張機能に同梱されたファイルに制限しています。また、厳しめの Content Security Policy、Webview メッセージ検証、モデル出力のテキスト描画によって、意図しないスクリプト実行や不正なリクエストを抑えています。
使い方
- VS Code Marketplace から拡張機能をインストールします。
- コマンドパレットから
PDF Translator: Open PDF を実行するか、.pdf ファイルを PDF Viewer Translator で開きます。
- 翻訳先言語を選択します。
Translate Page または Translate All をクリックします。
開発
npm install
npm run compile
VS Code でこのフォルダを開き、F5 を押すと Extension Development Host が起動します。
構成
src/extension.ts: 拡張機能のエントリーポイント
src/pdfTranslatorProvider.ts: PDF 用カスタムエディタと Webview メッセージ処理
src/translator.ts: VS Code Language Model API による翻訳処理
src/webview.ts: Webview HTML 生成
src/webview.js: PDF.js 表示、テキスト抽出、翻訳ページレイアウト
src/webview.css: Webview UI スタイル