robust-pdf-extraction
यह क्या करती है
यह स्किल AI एजेंट को PDF से टेक्स्ट लेने का चरण-दर-चरण तरीका देती है, चाहे वे टाइप किए हुए हों या स्कैन। यह उन लोगों के लिए है जो मिश्रित प्रकार के PDF संभालते हैं।
कब इस्तेमाल करें
- ✓जब आपके पास अज्ञात प्रकार के PDF हों और कुछ स्कैन हो सकते हों।
- ✓जब कोई PDF बहुत ज़रूरी हो और निकासी विफल होना वास्तविक समस्या बने।
- ✓जब आपको अलग-अलग फ़ॉर्मेट वाले PDF का बैच प्रोसेस करना हो।
Skill का लिंक
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/robust-pdf-extraction/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“इन बारह PDF से टेक्स्ट लीजिए। कुछ स्कैन किए हुए हैं, इसलिए हर तरीका तब तक आज़माइए जब तक टेक्स्ट न निकले।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
एजेंट जाँचता है कि हर PDF मौजूद है, फिर पहले pdfplumber आज़माता है। अगर उससे बहुत कम या कोई टेक्स्ट न मिले, तो वह pypdfium2 आज़माता है, और स्कैन किए गए दस्तावेज़ों के लिए OCR से पेज इमेज पढ़ता है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Robust PDF Extraction Workflow
This skill provides a systematic approach to extracting text from PDF files, handling both text-based and scanned/image-based documents through progressive fallback methods.
When to Use
- Processing PDFs of unknown or mixed types (text vs. scanned images)
- Critical document processing where extraction failure is not acceptable
- Batch processing multiple PDFs with varying formats
Workflow Steps
Step 1: Verify File Accessibility
Before attempting extraction, confirm the PDF exists and is readable:
# Check file exists and get basic info
ls -la /path/to/document.pdf
# Or search for files if location uncertain
find /path -name "*.pdf" -type f 2>/dev/null
Step 2: Attempt Primary Extraction (pdfplumber)
Start with pdfplumber for best text structure preservation:
import pdfplumber
def extract_with_pdfplumber(pdf_path):
text = ""
with pdfplumber.open(pdf_path) as pdf:
for page in pdf.pages:
page_text = page.extract_text()
if page_text:
text += page_text + "\n"
return text.strip()
Step 3: Fallback to Secondary Method (pypdfium2)
If pdfplumber returns empty or incomplete text:
import pdfium2
def extract_with_pypdfium2(pdf_path):
pdf = pdfium2.PdfDocument(pdf_path)
text = ""
for page in pdf:
text_page = page.get_textpage()
page_text = text_page.get_text_bounded()
if page_text:
text += page_text + "\n"
return text.strip()
Step 4: Fallback to Tertiary Method (pdftotext)
If pypdfium2 also fails, use command-line pdftotext:
pdftotext /path/to/document.pdf - 2>/dev/null
Or in Python:
import subprocess
def extract_with_pdftotext(pdf_path):
result = subprocess.run(
['pdftotext', pdf_path, '-'],
capture_output=True,
text=True
)
return result.stdout.strip()
Step 5: Detect Scanned/Image-Based PDFs
After each extraction attempt, verify text was actually extracted:
def is_meaningful_text(text, min_chars=50):
"""Check if extracted text is meaningful (not empty or just whitespace)"""
if not text:
return False
# Remove whitespace and check length
cleaned = ''.join(text.split())
return len(cleaned) >= min_chars
Step 6: OCR Fallback for Scanned Documents
If all text extraction methods return empty/insufficient text, the PDF is likely scanned. Use OCR:
import pdf2image
import pytesseract
from PIL import Image
def extract_with_ocr(pdf_path, dpi=300):
"""Extract text from scanned PDFs using OCR"""
text = ""
images = pdf2image.convert_from_path(pdf_path, dpi=dpi)
for image in images:
page_text = pytesseract.image_to_string(image)
text += page_text + "\n"
return text.strip()
Complete Workflow Function
def robust_pdf_extract(pdf_path):
"""
Extract text from PDF using progressive fallback methods.
Returns (text, method_used) tuple.
"""
methods = [
("pdfplumber", extract_with_pdfplumber),
("pypdfium2", extract_with_pypdfium2),
("pdftotext", extract_with_pdftotext),
]
for method_name, extract_func in methods:
try:
text = extract_func(pdf_path)
if is_meaningful_text(text):
return text, method_name
except Exception as e:
print(f"{method_name} failed: {e}")
continue
# All text methods failed - try OCR
try:
text = extract_with_ocr(pdf_path)
if is_meaningful_text(text):
return text, "ocr"
except Exception as e:
print(f"OCR failed: {e}")
return "", "failed"
Dependencies
Install required packages:
pip install pdfplumber pypdfium2 pdf2image pytesseract pillow
# Also need system packages:
# apt-get install poppler-utils tesseract-ocr # Debian/Ubuntu
# brew install poppler tesseract # macOS
Best Practices
- Log which method succeeded - helps identify document types for future optimization
- Set reasonable character thresholds - adjust
min_charsbased on expected document content - Handle exceptions gracefully - each method may fail for different reasons
- Consider DPI for OCR - higher DPI (300+) improves accuracy but increases processing time
- Cache results - if processing same PDFs repeatedly, store succe
अक्सर पूछे जाने वाले सवाल
एजेंट कौन सा तरीका पहले आज़माता है?
स्किल pdfplumber से शुरू करती है, क्योंकि वह टेक्स्ट की संरचना अच्छी तरह बनाए रखता है।
एजेंट OCR कब इस्तेमाल करता है?
जब बाकी तरीके खाली या अधूरा टेक्स्ट दें, जो आमतौर पर स्कैन का संकेत है, तब OCR इस्तेमाल होता है।
क्या स्किल फ़ाइल पहले जाँचती है?
हाँ, निकासी से पहले वह पक्का करती है कि हर PDF मौजूद और पढ़ने योग्य है।
जानकारी
लेखक का मूल विवरण
Multi-method PDF extraction with sequential fallback and OCR for scanned documents
repo: HKUDS/AgentPilot
लोकप्रियता
- GitHub स्टार
- 7.8k
- रैंकिंग में स्थान
- #12976
- लाइसेंस
- MIT
- अपडेट की गई
- 1/11/2026
कमेंट
- …
इस repository की और skills
agentpilot
7.8kआपके एजेंट को AgentPilot से प्रोजेक्ट को चरण-दर-चरण सुधारने में मदद करती है, जिसमें बदलाव सुझाए, परखे और स्कोर किए जाते हैं।
openspace
7.8kआपके एजेंट को OpenSpace सेट करने में मदद करती है, जो एजेंट स्किल्स सहेजता और वापस लाता है, और MCP के ज़रिए आपके AI ऐप से जुड़ता है।
rsi-arena
7.8kआपके एजेंट को AIME और Terminal-Bench जैसे मानक AI बेंचमार्क टेस्ट सेट करने और चलाने में मदद करती है, ताकि सुधार के तरीकों की तुलना हो सके।
experiment-guide
7.8kआपके एजेंट को छोटे प्रयोग बनाने, उनके नतीजे पढ़ने और जाँच के दौरान उपयोगी निष्कर्ष लिखने में मदद करती है।
मिलती-जुलती skills
feishu-doc
394kयह आपके एजेंट को document टूल से Feishu क्लाउड दस्तावेज़ पढ़ने, बनाने और बदलने में मदद करती है, जिसमें टेक्स्ट, इमेज और टेबल शामिल हैं।
feishu-drive
394kयह आपके एजेंट को बॉट के साथ साझा किए गए Feishu क्लाउड फ़ोल्डर में फ़ाइलें देखने, व्यवस्थित करने और उन पर टिप्पणी करने देती है।
feishu-perm
394kयह आपके एजेंट को Feishu फ़ाइल तक किसकी पहुंच है, यह जांचने और बदलने देती है, और आपके अनुरोध के लिए सबसे छोटी अनुमति चुनती है।