robust-pdf-read
できること
このスキルは、pdftotextツールを使ってPDFから読めるテキストを取り出す方法をAIエージェントに示します。PDFの読み取りが、読めない文字として返ってくる人向けです。
使う場面
- ✓ファイルリーダーが、PDFに対して生のバイナリや、base64の画像データ、文字化けを返すとき。
- ✓読めるテキストとして、PDFの文章が必要なとき。
- ✓PDFのテキストのレイアウトを、できるだけ元のまま保ちたいとき。
スキルのリンク
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/robust-pdf-read/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“私の賃貸契約のPDFを読んで、テキストを教えてください。ファイルリーダーは文字化けしか表示しません。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、通常のリーダーの出力にバイナリや文字化けがないかを確認します。見つかったら、レイアウトのオプションと改ページ文字を除くオプションを付けてpdftotextを実行し、テキストを標準出力に送って読みます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Robust PDF Text Extraction
Problem
Standard file reading tools (e.g., read_file) often fail to extract text from PDF documents. Instead of returning parsed text, they may return:
- Raw binary data
- Base64 encoded images
- Garbled characters or null bytes
This occurs because PDFs are complex binary formats, not plain text files. Attempts to parse them using general-purpose Python libraries (like PyMuPDF) in sandboxed environments may also fail due to missing dependencies or environment restrictions.
Solution
Use the pdftotext command-line utility (part of poppler-utils) via run_shell. This tool is commonly pre-installed in Linux environments and reliably extracts text content from PDFs.
Procedure
1. Detect Extraction Failure
When attempting to read a PDF:
- Check the content returned by
read_file. - If the content contains null bytes (
\x00), appears as base64, or is clearly binary/garbled, assume standard reading has failed.
2. Execute pdftotext
Run the following shell command using run_shell:
pdftotext -layout -nopgbrk <file_path> -
-layout: Maintains the physical layout of the text (optional but recommended).-nopgbrk: Prevents inserting form feed characters between pages.-: Outputs content to stdout instead of creating a new file.
3. Parse Output
Capture the stdout from the shell command. This string is the extracted text.
Example Usage
Scenario: You need to read document.pdf.
Step 1: Attempt standard read
content = read_file("document.pdf")
if "\x00" in content or not content.strip():
# Fallback needed
pass
Step 2: Fallback to shell
result = run_shell("pdftotext -layout -nopgbrk document.pdf -")
text = result.stdout
Prerequisites
- The environment must have
pdftotextinstalled (usually viapoppler-utils). - If
pdftotextis not found, attempt to install it (apt-get install poppler-utils) if permissions allow, or notify the user.
Benefits
- Reliability: Bypasses Python library dependency issues in sandboxes.
- Speed: Command-line tools are often faster than loading heavy Python libraries.
- Compatibility: Works consistently across most Linux-based agent environments.
よくある質問
読み取りが失敗したことはどう分かりますか?
ヌルバイト、base64のように見えるデータ、明らかに文字化けしたテキストを探します。
pdftotextのオプションは何をしますか?
layoutオプションはページのレイアウトを保ち、nopgbrkオプションは改ページ文字を取り除きます。
特別なインストールが必要ですか?
pdftotextはpoppler-utilsの一部で、Linuxのシステムには既に入っていることが多いとスキルは述べています。
詳細
作者による元の説明
Reliably extract text from PDFs using pdftotext when standard file reading fails.
repo: HKUDS/AgentPilot
人気
- GitHubのスター
- 7.8k
- ランキング
- #12977
- ライセンス
- MIT
- 更新日
- 2026/11/1
コメント
- …
このリポジトリの他のスキル
agentpilot
7.8kエージェントが、作業を準備し、変更案を提案してテストし、評価するAgentPilotのループを実行することで、プロジェクトを段階的に改善できるよう支援します。
openspace
7.8kエージェントが、スキルを保存し取り出すツールであるOpenSpaceをセットアップし、MCPを通じてAIアプリに接続できるよう支援します。
rsi-arena
7.8kエージェントが、AIMEやTerminal-Benchなどの標準的なAIベンチマークテストをセットアップして実行し、異なる改善方法を比較できるよう支援します。
experiment-guide
7.8kエージェントが、プログラムを改善する方法を調べる間に、小さな実験を計画し、その結果を読み、発見を記録できるよう支援します。
似ているスキル
feishu-doc
394kテキスト、画像、表を含むFeishuのクラウドドキュメントを、ドキュメントツールを使って読み、作成し、編集するようエージェントを支援します。
feishu-drive
394kボットと共有されたFeishuのクラウドフォルダ内のファイルを閲覧、整理、コメントできるようエージェントを支援します。
feishu-perm
394kFeishuのファイルにアクセスできる人を確認し、変更するようエージェントを支援します。依頼を満たす最小の権限を選びます。