pdf-text-extraction-9424c5
できること
このスキルは、通常のリーダーが失敗したときに、pdftotextでPDFファイルから読めるテキストを取り出す方法を説明します。AIが直接読めないPDF文書を扱う人向けです。
使う場面
- ✓PDFの読み取りが、文字化けやバイナリの内容を返すとき。
- ✓PDFにスキャン画像や複雑なバイナリ構造が含まれているとき。
- ✓PDFのテキストをファイルに保存したり、後の作業で使ったりしたいとき。
スキルのリンク
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-text-extraction-9424c5/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“document.pdfの文章を読んでください。通常のリーダーでは文字化けしたので、pdftotextで抽出してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
AIは、ファイルが存在するかを確認し、pdftotextを実行してテキストを取得し、それを直接使うか、必要なら一時的なテキストファイルに書き出します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
PDF Text Extraction via pdftotext
Problem
When using read_file on PDF documents, the function may return binary image data or garbled content instead of readable text. This occurs because PDFs can contain scanned images or complex binary structures that read_file cannot properly parse as text.
Solution
Use the pdftotext command-line utility via run_shell to extract clean text content from PDF files.
Steps
1. Verify PDF file exists
import os
pdf_path = "path/to/document.pdf"
if not os.path.exists(pdf_path):
raise FileNotFoundError(f"PDF not found: {pdf_path}")
2. Extract text using pdftotext
from tools import run_shell
# Extract text to stdout
result = run_shell(command=f"pdftotext '{pdf_path}' -", timeout=60)
pdf_text = result.stdout
# Alternative: extract to a temporary file
temp_txt = "/tmp/extracted.txt"
run_shell(command=f"pdftotext '{pdf_path}' '{temp_txt}'", timeout=60)
with open(temp_txt, 'r') as f:
pdf_text = f.read()
3. Handle parameter naming carefully
When calling read_file, be aware of the parameter name:
- Use
filetype="pdf"(notfile_type) - Some tool implementations may use different parameter names
# Correct parameter usage
content = read_file(file_path="doc.pdf", filetype="pdf")
# If this returns binary/garbled data, fall back to pdftotext
Common pdftotext Options
| Option | Description |
|---|---|
- |
Output to stdout |
-layout |
Maintain original layout |
-f <n> |
Start from page n |
-l <n> |
End at page n |
-q |
Quiet mode |
Example with options:
result = run_shell(command=f"pdftotext -layout -q '{pdf_path}' -", timeout=60)
Error Handling
from tools import run_shell
def extract_pdf_text(pdf_path):
"""Extract text from PDF using pdftotext with error handling."""
import os
if not os.path.exists(pdf_path):
raise FileNotFoundError(f"PDF not found: {pdf_path}")
result = run_shell(command=f"pdftotext '{pdf_path}' -", timeout=60)
if result.returncode != 0:
raise RuntimeError(f"pdftotext failed: {result.stderr}")
return result.stdout.strip()
When to Use This Pattern
read_filereturns binary data, garbled text, or image content for a PDF- You need searchable/processable text from PDF documents
- The PDF contains text (not just scanned images - for those, consider OCR tools)
Prerequisites
pdftotextmust be installed (part ofpoppler-utilson Debian/Ubuntu,poppleron macOS via Homebrew)- Verify availability:
run_shell(command="which pdftotext")
よくある質問
なぜ先にファイルの存在を確認するのですか?
PDFのパスが間違っている場合に、ガイドが分かりやすいエラーで止まるからです。
read_fileのパラメータのコツは?
読み取りツールを呼ぶときは、file_typeではなくfiletypeを使うようガイドは勧めています。
出力はどこに出せますか?
画面に表示することも、テキストファイルに書き出すこともできます。
詳細
作者による元の説明
Extract text from PDF files using pdftotext when read_file returns binary data
repo: HKUDS/AgentPilot
人気
- GitHubのスター
- 7.8k
- ランキング
- #12932
- ライセンス
- 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のファイルにアクセスできる人を確認し、変更するようエージェントを支援します。依頼を満たす最小の権限を選びます。