pdf-text-extraction-fallback-85d5ca
Ce qu’il fait
Ce skill est une solution de secours pour les PDF dont le contenu revient sous forme de données binaires depuis le lecteur. Il s'adresse aux personnes qui ont besoin du texte d'un fichier PDF pour poursuivre leur travail.
Quand l’utiliser
- ✓Quand le lecteur de fichiers renvoie la structure brute du PDF ou des données binaires.
- ✓Quand le texte du PDF est nécessaire pour des synthèses, des analyses ou une extraction de données.
- ✓Quand pdftotext n'est pas installé et qu'une bibliothèque Python est nécessaire à la place.
Lien du skill
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-text-extraction-fallback-85d5ca/SKILL.mdCopiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.
Comment l’utiliser
Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.
Message prêt à coller
Pour Claude Code, Codex ou Cursor : lancez-la dans le dossier du projet et le skill est installé.
Téléchargez le SKILL.md et placez-le dans le dossier de skills de votre agent.
Exemple de demande à votre IA
“Le lecteur de fichiers n'affiche que le code PDF brut de mon document. Demande à un assistant d'extraire le texte avec pdftotext, ou avec pdfplumber si celui-ci n'est pas disponible.”
5 nouveaux skills par semaine. 1 minute de lecture.
Comment ça marche
L'IA confie une tâche d'extraction claire à un assistant shell, en lui demandant de lancer pdftotext et d'enregistrer le texte, avec pdfplumber comme solution Python de secours.
Contenu technique (SKILL.md original)
Texte original de l’auteur, en anglais, directement depuis GitHub.
PDF Text Extraction Fallback
Use this skill when read_file returns binary data or garbled content for PDF files instead of readable text. This workflow provides a reliable fallback using command-line PDF tools.
When to Use
read_filewithfiletype: pdfreturns binary data, unreadable characters, or errors- You need to extract text from a PDF to process its contents
- Standard file reading methods fail to extract usable text
Step-by-Step Instructions
Step 1: Detect Binary/Unreadable PDF Output
After attempting to read a PDF with read_file, check if the output is:
- Binary data (contains null bytes, non-printable characters)
- Garbled text with many special characters
- Empty or truncated content
# Example of problematic output from read_file
%PDF-1.4
1 0 obj
<< /Type /Catalog ...
If the output looks like raw PDF structure or binary, proceed to Step 2.
Step 2: Use shell_agent with PDF Tools
Invoke shell_agent to extract text using pdftotext (preferred) or pdfplumber (Python fallback):
Task: Extract all text content from <filename.pdf> using pdftotext or pdfplumber.
Output the extracted text in readable format. If pdftotext is not available, use Python with pdfplumber library.
Example shell_agent invocation:
shell_agent task="Extract text from Move_Out_Inspection_Tracker.pdf using pdftotext. Save output to a .txt file and return the content."
Step 3: Validate Extracted Content
After extraction, validate that the content contains expected text patterns:
# Validation checklist
def validate_pdf_extraction(text, expected_patterns=None):
checks = [
bool(text.strip()), # Not empty
len(text) > 50, # Has substantial content
not text.startswith('%PDF'), # Not raw PDF structure
]
if expected_patterns:
for pattern in expected_patterns:
checks.append(pattern.lower() in text.lower())
return all(checks)
Common expected patterns to check:
- Document-specific keywords (e.g., "inspection", "resident", "date")
- Expected data formats (dates, names, IDs)
- Minimum word count threshold
Step 4: Handle Extraction Failures
If validation fails:
Try alternative tool: If
pdftotextfailed, trypdfplumber:shell_agent task="Extract text from <file.pdf> using Python pdfplumber library. Handle any encoding issues."Try OCR fallback: For scanned PDFs:
shell_agent task="This PDF may be scanned. Use pytesseract or similar OCR tool to extract text from <file.pdf>."Report specific error: Document what patterns were expected but not found.
Step 5: Proceed with Data Processing
Once validated text is obtained:
- Parse the extracted text for required data
- Store or process the content as needed
- Continue with the original task workflow
Code Example
# Complete extraction workflow
def extract_pdf_text_fallback(pdf_path, expected_patterns=None):
"""Extract text from PDF with fallback handling."""
# Step 1: Try read_file first
content = read_file(filetype="pdf", file_path=pdf_path)
# Step 2: Check if binary/unreadable
if is_binary_or_garbled(content):
# Step 3: Use shell_agent fallback
result = shell_agent(
task=f"Extract all text from {pdf_path} using pdftotext. Return the text content."
)
content = result.stdout
# Step 4: Validate
if not validate_pdf_extraction(content, expected_patterns):
# Try pdfplumber as secondary fallback
result = shell_agent(
task=f"Extract text from {pdf_path} using Python pdfplumber library."
)
content = result.stdout
return content
def is_binary_or_garbled(text):
"""Check if text appears to be binary or unreadable."""
if not text:
return True
if text.startswith('%PDF'):
return True
# Check for high ratio of non-printable characters
non_printable = sum(1 for c in text if ord(c) > 127 or ord(c) < 32)
return non_printable / len(text) > 0.3
Tips
- pdftotext is typically faster and pre-installed on many systems
- pdfplumber handles complex layouts better but requires Python
- For scanned PDFs, you'll need OCR tools (tesseract, pytesseract)
- Always validate extracted content matches your expected data patterns
- Save intermediate extraction results fo
Questions fréquentes
Que demande l'IA à l'assistant ?
Elle lui demande d'extraire le texte avec pdftotext et de l'enregistrer dans un fichier texte.
Quelle bibliothèque Python sert de secours ?
Le guide cite pdfplumber comme solution Python de secours.
Quel résultat est attendu ?
Un texte lisible extrait du document, enregistré dans un fichier.
Détails
Description originale de l’auteur
Fallback workflow for extracting text from PDFs when read_file returns binary data
repo: HKUDS/AgentPilot
Popularité
- Étoiles GitHub
- 7.8k
- Position au classement
- #12933
- Licence
- MIT
- Mis à jour
- 01/11/2026
Commentaires
- …
Autres skills de ce dépôt
agentpilot
7.8kAide votre agent à améliorer un projet étape par étape, en préparant une tâche et en lançant la boucle AgentPilot qui propose, teste et note les changements.
openspace
7.8kAide votre agent à installer OpenSpace, un outil qui enregistre et retrouve les skills des agents, et à le relier à votre application IA grâce à MCP.
rsi-arena
7.8kAide votre agent à configurer et lancer des tests de référence standard en IA, comme AIME et Terminal-Bench, pour comparer différentes méthodes d'amélioration.
experiment-guide
7.8kAide votre agent à planifier de petites expériences, à lire leurs résultats et à noter les conclusions pendant qu'il cherche comment améliorer un programme.
Skills similaires
feishu-doc
394kAide votre agent à lire, créer et modifier des documents cloud Feishu, y compris du texte, des images et des tableaux, grâce à l'outil de document.
feishu-drive
394kPermet à votre agent de parcourir, organiser et commenter des fichiers d'un dossier cloud Feishu partagé avec le bot.
feishu-perm
394kAide votre agent à vérifier et modifier qui peut accéder à un fichier Feishu, en choisissant la plus petite autorisation qui répond à votre demande.