本文へスキップ
Skillpedia
PDF・Word・スライド7.8k · #12935

pdf-text-extraction

できること

このスキルは、組み込みのハンドラーが信頼できないときに、PDFのテキストを取り出す複数の方法を挙げます。分析や要約のために、読めるPDFの内容が必要な人向けです。

使う場面

  • ✓PDFの読み取りが、画像のデータ、エラー、不完全な内容を返すとき。
  • ✓PDFのページ数やメタデータが必要なとき。
  • ✓PDFから表のデータが必要で、単純な方法では足りないとき。

スキルのリンク

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-text-extraction/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-text-extraction/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“組み込みのPDFリーダーがレポートで失敗しています。テキストを取り出し、何ページあるかも教えてください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

AIは、テキストにはpdftotext、メタデータにはpdfinfo、Pythonの方法にはPyMuPDF、表にはpdfplumberを選び、選んだコマンドをシェルから実行します。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

PDF Text Extraction (Fallback Method)

When to Use This Skill

Use this skill when read_file with filetype='pdf':

  • Returns binary image data instead of text
  • Produces errors or incomplete content
  • Fails to extract structured data reliably

The built-in PDF handler is unreliable for structured text extraction. Shell-based tools provide more robust alternatives.

Available Methods

Method 1: pdftotext (Recommended)

# Extract text from PDF to stdout
pdftotext /path/to/file.pdf -

# Extract text to a file
pdftotext /path/to/file.pdf output.txt

# Preserve layout (maintains spacing/structure)
pdftotext -layout /path/to/file.pdf output.txt

Usage in agent:

run_shell command="pdftotext -layout /path/to/document.pdf -"

Method 2: pdfinfo (Metadata)

# Get PDF metadata (pages, author, creation date, etc.)
pdfinfo /path/to/file.pdf

Usage in agent:

run_shell command="pdfinfo /path/to/document.pdf"

Method 3: Python with PyMuPDF (fitz)

import fitz  # PyMuPDF

doc = fitz.open("/path/to/file.pdf")
text = ""
for page in doc:
    text += page.get_text()
doc.close()
print(text)

Usage in agent:

run_shell command="python3 -c \"import fitz; doc=fitz.open('file.pdf'); print(''.join(p.get_text() for p in doc))\""

Method 4: Python with pdfplumber (Tables)

import pdfplumber

with pdfplumber.open("/path/to/file.pdf") as pdf:
    for page in pdf.pages:
        text = page.extract_text()
        tables = page.extract_tables()  # For tabular data

Usage in agent:

run_shell command="python3 -c \"import pdfplumber; pdf=pdfplumber.open('file.pdf'); print(''.join(p.extract_text() or '' for p in pdf.pages))\""

Workflow

  1. Try pdftotext first - Fastest and most reliable for plain text

    run_shell command="pdftotext -layout /path/to/file.pdf -"
    
  2. If pdftotext unavailable, check for Python libraries

    run_shell command="python3 -c \"import fitz; print('PyMuPDF available')\""
    
  3. For table/structured data, use pdfplumber

    run_shell command="python3 -c \"import pdfplumber; ...\""
    
  4. Verify extraction succeeded - Check output contains readable text, not binary data

Installation Notes

If tools are not available:

# Ubuntu/Debian
apt-get install poppler-utils  # pdftotext, pdfinfo

# Install Python libraries
pip install pymupdf pdfplumber

Anti-Patterns to Avoid

  • Do NOT rely solely on read_file with filetype='pdf' for critical text extraction
  • Do NOT assume PDF text is in any particular order - verify extracted content
  • Do NOT use image-based extraction unless the PDF is scanned (use OCR instead)

Example: Complete Extraction Pattern

# Step 1: Try pdftotext
RESULT=$(pdftotext -layout /path/to/form.pdf - 2>/dev/null)

# Step 2: Verify we got text, not error
if [ -z "$RESULT" ]; then
    # Fallback to Python
    RESULT=$(python3 -c "import fitz; doc=fitz.open('/path/to/form.pdf'); print(''.join(p.get_text() for p in doc))")
fi

# Step 3: Use extracted text
echo "$RESULT"
よくある質問

pdfinfoは何を表示しますか?

ページ数、タイトル、作成者、作成日などのメタデータを表示します。

pdfplumberはいつ役立ちますか?

PDFから表を抽出する場合に役立つとガイドは勧めています。

組み込みのハンドラーは常に信頼できないのですか?

構造化されたテキストの抽出には信頼できないので、シェルのツールを優先するとガイドは述べています。

詳細

作者による元の説明

Extract text from PDFs using shell tools when read_file fails

repo: HKUDS/AgentPilot

人気

GitHubのスター
7.8k
ランキング
#12935
ライセンス
MIT
更新日
2026/11/1

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル