pdf-text-extraction-fallback
できること
このスキルは、組み込みのファイルリーダーが失敗したときに、pdftotextを使ってPDFのテキストを取り出す方法を説明します。画像や複雑な書式を含むPDFを扱う人向けです。
使う場面
- ✓PDFの読み取りが、バイナリや画像のデータを返すとき。
- ✓PDFに埋め込まれた画像や複雑な書式があるとき。
- ✓タスクで使うために、PDFの読めるテキストが必要なとき。
スキルのリンク
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-text-extraction-fallback/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“ファイルリーダーが私のPDFからバイナリのデータを返します。呼び出しの設定を確認して、pdftotextでテキストを取り出してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
AIは、読み取りの呼び出しが正しいパラメータ名を使っていることを確認し、バイナリの出力を見分けたうえで、pdftotextを実行して、テキストを標準出力に表示します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
PDF Text Extraction Fallback
When to Use This Skill
Use this skill when read_file with filetype="pdf" returns binary/image data instead of readable text content. This is a common issue with PDF files that contain embedded images or complex formatting.
Steps
1. Validate Parameters First
Before attempting extraction, ensure you're using the correct parameter name:
- Use
filetype(notfile_type) for theread_filefunction - Incorrect parameter names can cause silent failures
# Correct
read_file(filetype="pdf", file_path="document.pdf")
# Incorrect - may fail silently
read_file(file_type="pdf", file_path="document.pdf")
2. Detect Binary Data Issue
After calling read_file, check if the result contains:
- Garbled/binary characters
- Image data representations (e.g.,
b'...'byte strings with non-text content) - Unreadable or corrupted-looking content
If yes, proceed with the pdftotext workaround.
3. Extract Text via pdftotext
Use run_shell to call pdftotext, which extracts text directly from PDF files:
# Extract text to stdout
result = run_shell(command="pdftotext /path/to/document.pdf -")
text_content = result.stdout
The - flag tells pdftotext to output to stdout instead of creating a file.
4. Handle Output and Errors
result = run_shell(command="pdftotext /path/to/document.pdf -")
if result.stderr:
# Check for errors like "pdftotext not found"
# May need to install poppler-utils
pass
text_content = result.stdout
# text_content now contains the extracted text
Example Workflow
# Step 1: Try normal read with correct parameters
content = read_file(filetype="pdf", file_path="reference.pdf")
# Step 2: Check if content is readable
if not content or looks_like_binary(content):
# Step 3: Fall back to pdftotext
result = run_shell(command="pdftotext reference.pdf -")
text_content = result.stdout
# Step 4: Verify extraction succeeded
if result.stderr:
# Handle error (e.g., install pdftotext)
pass
Installation Notes
pdftotext is part of the poppler-utils package:
- Debian/Ubuntu:
apt-get install poppler-utils - macOS:
brew install poppler - Many Linux environments: Pre-installed
Alternative: Output to File
If stdout approach has issues, output to a temporary file:
run_shell(command="pdftotext /path/to/document.pdf /tmp/output.txt")
text_content = read_file(filetype="txt", file_path="/tmp/output.txt")
Best Practices
- Always validate the
filetypeparameter spelling before troubleshooting - Check both stdout and stderr from pdftotext
- For multi-page PDFs, pdftotext preserves page breaks with form feeds
- This method works better for text-based PDFs than image-scanned PDFs
よくある質問
なぜパラメータ名が重要なのですか?
パラメータ名が間違っていると、エラーが出ずに失敗することがあるとガイドは述べています。
バイナリの出力はどう見分けますか?
結果の中にバイナリの文字や画像データのマーカーがないかを探します。
コマンドのダッシュは何をしますか?
pdftotextに、ファイルではなく画面にテキストを出すよう伝えます。
詳細
作者による元の説明
Extract text from PDFs using pdftotext when read_file returns binary data
repo: HKUDS/AgentPilot
人気
- GitHubのスター
- 7.8k
- ランキング
- #12934
- ライセンス
- 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のファイルにアクセスできる人を確認し、変更するようエージェントを支援します。依頼を満たす最小の権限を選びます。