pdf-text-extraction
What it does
This skill lists several ways to extract PDF text when the built-in handler is unreliable. It is for people who need readable PDF content for analysis or summaries.
When to use it
- ✓When reading a PDF returns image data, errors or incomplete content.
- ✓When I need the page count or metadata of a PDF.
- ✓When I need table data from a PDF and the simple methods are not enough.
Skill link
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-text-extraction/SKILL.mdCopy 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
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“The built-in PDF reader is failing on my report. Please pull out the text and also tell me how many pages it has.”
5 new skills a week. 1 minute to read.
How it works
The AI picks among pdftotext for text, pdfinfo for metadata, PyMuPDF for a Python route, or pdfplumber for tables, and runs the chosen command from the shell.
Technical content (original SKILL.md)
Original text by the author, straight from 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
Try pdftotext first - Fastest and most reliable for plain text
run_shell command="pdftotext -layout /path/to/file.pdf -"If pdftotext unavailable, check for Python libraries
run_shell command="python3 -c \"import fitz; print('PyMuPDF available')\""For table/structured data, use pdfplumber
run_shell command="python3 -c \"import pdfplumber; ...\""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_filewithfiletype='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"
FAQ
What does pdfinfo show?
It shows metadata such as the number of pages, title, author and creation date.
When is pdfplumber useful?
The guide suggests it for extracting tables from PDFs.
Is the built-in handler always unreliable?
The guide says it is unreliable for structured text extraction, so shell tools are preferred.
Details
Original description by the author
Extract text from PDFs using shell tools when read_file fails
repo: HKUDS/AgentPilot
Popularity
- GitHub stars
- 7.8k
- Ranking position
- #12935
- License
- MIT
- Updated
- 11/1/2026
Comments
- …
More skills from this repository
agentpilot
7.8kHelps your agent improve a project step by step by preparing a task and running the AgentPilot loop that proposes, tests and scores changes.
openspace
7.8kHelps your agent set up OpenSpace, a tool that stores and fetches agent skills, and connect it to your AI app through MCP.
rsi-arena
7.8kHelps your agent set up and run standard AI benchmark tests, such as AIME and Terminal-Bench, to compare different improvement methods.
experiment-guide
7.8kHelps your agent plan small experiments, read their results and record findings while it investigates how to improve a program.
Similar skills
feishu-doc
394kHelps your agent read, create, and edit Feishu cloud documents, including text, images, and tables, using the document tool.
feishu-drive
394kLets your agent browse, organize, and comment on files in a Feishu cloud folder that has been shared with the bot.
feishu-perm
394kHelps your agent check and change who can access a Feishu file, choosing the smallest permission that meets your request.