Skip to content
Skillpedia
PDF, Word & slides7.8k · #12968

reliable-pdf-extraction

What it does

This skill guides the AI agent to read PDFs using pdftotext, pdfinfo or Python libraries when the built-in reader gives bad output. It is for people who work with PDF documents through an AI.

When to use it

  • ✓When the standard PDF reader returns binary data, errors or empty text.
  • ✓When you need text from a PDF that will be used for structured data extraction.
  • ✓When you want to check a PDF's details before reading its text.

Skill link

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

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/reliable-pdf-extraction/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“Read the report PDF I attached and give me the main points. The normal PDF reader gives errors.”

5 new skills a week. 1 minute to read.

How it works

The agent first tries the normal reader and checks the output. If the result is garbled or empty, it runs pdftotext or pdfinfo through the shell, or uses a Python library, and then reads the extracted text.

Technical content (original SKILL.md)

Original text by the author, straight from 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

  1. Attempt read_file with filetype='pdf' first (in case it works)

  2. Check output - If you receive:

    • Binary/garbage data
    • Error messages
    • Empty or truncated content
    • Image data instead of text
  3. Fall back to one of the extraction methods above:

    • Use pdftotext via run_shell for quick text extraction
    • Use pdfplumber via execute_code_sandbox for structured data/tables
    • Use PyMuPDF for complex layouts or when you need more control
  4. 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
FAQ

What does pdfinfo show?

It shows details such as the page count and page size, which help before extraction.

Does the agent always try the normal reader first?

Yes, the skill says to try it first and switch only when the output looks wrong.

Which Python libraries are named?

The skill names PyMuPDF for general text and pdfplumber for tables.

Details

Original description by the author

Use shell commands or Python libraries to extract PDF text when read_file PDF handler fails

repo: HKUDS/AgentPilot

Popularity

GitHub stars
7.8k
Ranking position
#12968
License
MIT
Updated
11/1/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills