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.
- Auto-translate the current page or translate the whole document on demand.
- Choose a target language from the toolbar.
- Choose
Fast,Balanced, orAccuratetranslation 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 PDFfrom the command palette, or open a.pdffile withPDF Viewer Translator. - Select a target language.
- The current page translates automatically. Click
Translate Allto translate the whole document.
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 pointsrc/pdfTranslatorProvider.ts: PDF custom editor and webview message handlingsrc/translator.ts: Translation through the VS Code Language Model APIsrc/webview.ts: Webview HTML generationsrc/webview.js: PDF.js rendering, text extraction, and translated page layoutsrc/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 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 スタイル