reliable-pdf-extraction
できること
このスキルは、組み込みのリーダーが悪い出力を返すときに、pdftotext、pdfinfo、またはPythonのライブラリを使ってPDFを読む方法をAIエージェントに示します。AIを通してPDF文書を扱う人向けです。
使う場面
- ✓標準のPDFリーダーが、バイナリのデータ、エラー、空のテキストを返すとき。
- ✓構造化されたデータの抽出に使うPDFのテキストが必要なとき。
- ✓テキストを読む前に、PDFの詳細を確かめたいとき。
スキルのリンク
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/reliable-pdf-extraction/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“添付した報告書のPDFを読んで、要点を教えてください。通常のPDFリーダーがエラーを返します。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、まず通常のリーダーを試して出力を確認します。結果が文字化けしていたり空だったりすれば、pdftotextかpdfinfoをシェルから実行するか、Pythonのライブラリを使い、抽出されたテキストを読みます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Reliable PDF Text Extraction
Problem
The read_file tool with filetype='pdf' often returns binary image data, errors, or unusable output when attempting to extract text from PDF documents. This makes it unreliable for structured data extraction tasks.
Solution
Use run_shell with command-line tools (pdftotext, pdfinfo) or execute_code_sandbox with Python libraries (PyMuPDF, pdfplumber) to extract PDF text content reliably.
Methods
Method 1: pdftotext (Recommended for simple extraction)
# Extract all text to stdout
pdftotext input.pdf -
# Or extract to file
pdftotext input.pdf output.txt
cat output.txt
Method 2: pdfinfo (For metadata)
pdfinfo input.pdf
Method 3: Python with PyMuPDF (fitz)
import fitz # PyMuPDF
doc = fitz.open("input.pdf")
text = ""
for page in doc:
text += page.get_text()
print(text)
doc.close()
Method 4: Python with pdfplumber (Better for tables/structured data)
import pdfplumber
with pdfplumber.open("input.pdf") as pdf:
for page in pdf.pages:
text = page.extract_text()
print(text)
# For tables:
# tables = page.extract_tables()
Workflow
Attempt
read_filewithfiletype='pdf'first (in case it works)Check output - If you receive:
- Binary/garbage data
- Error messages
- Empty or truncated content
- Image data instead of text
Fall back to one of the extraction methods above:
- Use
pdftotextviarun_shellfor quick text extraction - Use
pdfplumberviaexecute_code_sandboxfor structured data/tables - Use
PyMuPDFfor complex layouts or when you need more control
- Use
Process the extracted text for your task
Example Usage
# Via run_shell
result = run_shell(command="pdftotext document.pdf -")
pdf_text = result.stdout
# Via execute_code_sandbox
code = """
import pdfplumber
with pdfplumber.open("/path/to/document.pdf") as pdf:
for page in pdf.pages:
print(page.extract_text())
"""
result = execute_code_sandbox(code=code)
pdf_text = result.stdout
Tips
- pdftotext is fastest and most reliable for plain text extraction
- pdfplumber excels at extracting tables and preserving layout
- PyMuPDF offers the most control for complex PDF structures
- Always check if the PDF is scanned/image-based (may need OCR tools like
tesseract) - Some PDFs have copy protection that may prevent text extraction
よくある質問
pdfinfoは何を表示しますか?
ページ数やページのサイズなど、抽出の前に役立つ詳細を表示します。
エージェントは必ず通常のリーダーから試しますか?
はい。スキルは、まず試し、出力がおかしいときにだけ切り替えるよう述べています。
どのPythonのライブラリが挙げられていますか?
一般的なテキストにはPyMuPDF、表にはpdfplumberが挙げられています。
詳細
作者による元の説明
Use shell commands or Python libraries to extract PDF text when read_file PDF handler fails
repo: HKUDS/AgentPilot
人気
- GitHubのスター
- 7.8k
- ランキング
- #12968
- ライセンス
- 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のファイルにアクセスできる人を確認し、変更するようエージェントを支援します。依頼を満たす最小の権限を選びます。