pdftotext-fallback
できること
このスキルは、シェルのpdftotextを使ってPDFのテキストを取り出す回復の方法です。PDFを読むツールが使えない結果を返す人向けです。
使う場面
- ✓PDFの読み取りが、バイナリや画像のデータを返すとき。
- ✓サンドボックスでのPythonによるPDFの抽出が失敗、または文字化けしたテキストを返すとき。
- ✓単純なコマンドで足りる、信頼できるPDFのテキストが必要なとき。
スキルのリンク
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdftotext-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からそのまま表示しています。
pdftotext Fallback for PDF Text Extraction
When to Use
Apply this pattern when:
read_fileon a PDF returns binary/image data instead of readable text- Python-based PDF extraction (PyMuPDF, pdfplumber, etc.) in
execute_code_sandboxfails or returns garbled content - You need reliable text extraction from PDF files as a recovery strategy
Why This Works
The pdftotext utility (from poppler-utils) is a mature, command-line tool that handles many PDF edge cases that confuse Python libraries or the read_file tool. It's pre-installed on most Linux systems and provides consistent, reliable text extraction.
Steps
Step 1: Detect the Failure
Recognize extraction failure when:
read_filereturns binary content, image data, or garbled text- Error messages indicate encoding issues or unsupported formats
- Python PDF libraries in sandbox fail with import errors or extraction failures
Step 2: Use pdftotext via run_shell
Extract to stdout (recommended for quick extraction):
pdftotext /path/to/file.pdf -
The - argument outputs directly to stdout for easy capture in your tool response.
Example:
run_shell("pdftotext document.pdf -")
Step 3: Handle Complex PDFs
Preserve layout (maintains original formatting):
pdftotext -layout /path/to/file.pdf -
Extract to a file (for large PDFs):
pdftotext /path/to/file.pdf /path/to/output.txt
Then read the output file with read_file.
Handle encoded text:
pdftotext -enc UTF-8 /path/to/file.pdf -
Step 4: Verify and Continue
- Check the extracted text for completeness
- If text is still garbled, the PDF may be image-based (scanned) - consider OCR tools
- Proceed with your task using the extracted text
Code Examples
Basic extraction:
# Simple text extraction
text = run_shell("pdftotext document.pdf -")
With error handling:
# Try extraction, check for success
result = run_shell("pdftotext document.pdf - && echo 'SUCCESS' || echo 'FAILED'")
Multi-page PDF with layout:
# Preserve tables and formatting
text = run_shell("pdftotext -layout document.pdf -")
Troubleshooting
| Issue | Solution |
|---|---|
pdftotext: command not found |
Install poppler-utils: apt-get install poppler-utils |
| Garbled/special characters | Try -enc UTF-8 or -enc ASCII7 |
| Missing formatting | Use -layout flag |
| Scanned PDF (no text) | Requires OCR (e.g., tesseract), not text extraction |
| Large PDF timeout | Extract to file instead of stdout |
Limitations
- Does not work on image-only (scanned) PDFs without embedded text
- May lose complex formatting, tables, or embedded objects
- Requires poppler-utils to be installed (common on Linux, may need installation on other systems)
Related Tools
pdfinfo: Get PDF metadata (pages, size, etc.)pdftoppm: Convert PDF pages to imagestesseract: OCR for scanned PDFs
よくある質問
なぜpdftotextは信頼できるとされるのですか?
PDFの多くの特殊なケースを扱える、成熟したコマンドラインツールだとガイドは説明しています。
ダッシュは何をしますか?
抽出したテキストを画面に送り、AIが取り込めるようにします。
大きなPDFのオプションは?
画面ではなく、ファイルに抽出することをガイドは勧めています。
詳細
作者による元の説明
Recover PDF text extraction when read_file returns binary data by using pdftotext via shell
repo: HKUDS/AgentPilot
人気
- GitHubのスター
- 7.8k
- ランキング
- #12942
- ライセンス
- 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のファイルにアクセスできる人を確認し、変更するようエージェントを支援します。依頼を満たす最小の権限を選びます。