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

pdf-extract-progressive-tools

できること

このスキルは、最初の方法で読めないデータが返されたときに、PDFのテキストを取り出すための段階的な順序を示します。PDFからバイナリや文字化けしたデータを受け取ってしまうAIの人向けです。

使う場面

  • ✓PDFを読むと、テキストではなくバイナリや画像のデータが返されるとき。
  • ✓要約や分析のために、確実なPDFのテキストが必要なとき。
  • ✓簡単なツールでは読めない、複雑なPDFのとき。

スキルのリンク

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-download-extract-fallback-enhanced-899f5b/SKILL.md

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

使い方

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

貼り付け用メッセージ

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

AIへの頼み方の例

“AIが私のPDFから文字化けしたテキストを返し続けます。まず簡単な方法を試し、きれいなテキストが得られるまで、ほかのツールを順に試してください。”

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

仕組み

AIは、まず単純なファイル読み取りを試し、失敗すればシェルからpdftotextを実行し、最後にサンドボックスでPythonのPyMuPDFのスクリプトを使います。最後にテキストの品質を確認します。

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

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

PDF Text Extraction with Progressive Tool Fallback

This skill provides a robust workflow for extracting text from PDF documents using a sequenced approach with agent tools, with explicit fallback mechanisms based on observed tool behavior.

Critical Insight from Execution Data

read_file often returns binary/image data for PDFs, not extracted text. When this occurs, immediately escalate to run_shell with pdftotext before attempting Python-based extraction.

Entry Point: Determine Your Starting Point

Before beginning, identify your scenario:

Scenario Start Here Skip
PDF already on local disk Step 1 (read_file attempt) Download steps
PDF at a web URL Download first, then Step 1 None
PDF content already extracted Step 4 (Quality verification) Steps 1-3

Overview

PDF extraction failures cascade when tool sequencing is unclear. This workflow ensures maximum success rate through explicit tool progression:

  1. read_file - Quick attempt, but may return binary data
  2. run_shell + pdftotext - Reliable extraction when read_file fails
  3. execute_code_sandbox + PyMuPDF - Final fallback for complex PDFs

Step-by-Step Instructions

Step 1: Attempt read_file First

Always try the simplest approach first:

Tool: read_file
Path: document.pdf

Expected outcome: Extracted text content

Critical check: Examine the returned content:

  • ✅ Text visible: Proceed to Step 4 (Quality verification)
  • ⚠️ Binary/image data detected: Immediately proceed to Step 2
  • ❌ File not found: Verify path or download first

Binary data indicators:

  • Content starts with %PDF- header without text extraction
  • Content appears as garbled characters or base64
  • Content contains PNG/JPEG markers within PDF wrapper
  • File size seems reasonable but no readable text

Step 2: Escalate to run_shell with pdftotext

When read_file returns binary data, do NOT attempt execute_code_sandbox yet. Use run_shell immediately:

Tool: run_shell
Command: pdftotext document.pdf document.txt

If pdftotext is not available:

Tool: run_shell
Command: apt-get update && apt-get install -y poppler-utils && pdftotext document.pdf document.txt

Then read the extracted text:

Tool: read_file
Path: document.txt

Expected outcome: Clean text extraction

If this fails:

  • Check if file is password-protected
  • Check if file is corrupted (run file document.pdf)
  • Proceed to Step 3

Step 3: Final Fallback to execute_code_sandbox with PyMuPDF

Only attempt this if Steps 1-2 fail:

Tool: execute_code_sandbox
Language: python
Code: |
  import fitz  # PyMuPDF
  
  try:
      doc = fitz.open("document.pdf")
      text = ""
      for page in doc:
          text += page.get_text()
      doc.close()
      
      with open("document_pymupdf.txt", "w") as f:
          f.write(text)
      
      print("SUCCESS: Extracted {} characters".format(len(text)))
  except Exception as e:
      print(f"FAILED: {e}")

Then read the result:

Tool: read_file
Path: document_pymupdf.txt

Step 4: Quality Verification

Regardless of which method succeeded, verify extraction quality:

  1. Check text length: Should be proportional to PDF pages (~500-2000 chars per page)
  2. Check readability: Text should form coherent sentences
  3. Check for truncation: Look for cut-off words or missing sections
  4. Compare methods: If multiple methods worked, compare outputs

If quality is poor:

  • Try alternative extraction tools (pdfplumber, camelot-py for tables)
  • Consider OCR for scanned documents
  • Document limitations clearly

Step 5: Graceful Degradation to Domain Knowledge

If all extraction methods fail:

  1. Document the specific failure mode for each tool attempted
  2. Extract any partial content that was successfully retrieved
  3. Supplement missing content from established domain knowledge
  4. Clearly mark which portions are from source vs. generated from knowledge
  5. Provide citations for any claimed requirements or specifications

Example degradation note:

NOTE: Source document [path/URL] was inaccessible due to [specific tool failures].
Content below combines partial extraction with established domain knowledge 
for [topic]. All claims verified against [alternative sources] where possible.

Tool Failure Log:
- read_file: Returned binary data (no text extraction)
- run_shell/pdftotext: Comman
よくある質問

なぜ単純な読み取りから始めるのですか?

最も速い試みだからです。ただし、バイナリデータを返すこともあるとガイドは述べています。

なぜpdftotextがPythonより先なのですか?

制限のある環境では、シェルツールの方が信頼できたとガイドは述べています。

テキストの品質は確認されますか?

はい。抽出したテキストの品質を確かめるステップがガイドに含まれています。

詳細

作者による元の説明

Progressive tool-chain PDF extraction with explicit read_file, run_shell, and execute_code_sandbox sequencing

repo: HKUDS/AgentPilot

人気

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

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

0

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

コメント

  • …

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

似ているスキル