pdf-extraction-fallbacks-7d54a9
यह क्या करती है
यह स्किल उन PDF से टेक्स्ट लेने का काम है जो डाउनलोड होने या साफ़ निकलने में विफल हो सकती हैं। यह उन लोगों के लिए है जो नियामक या एजेंसी के दस्तावेज़ जुटाते हैं।
कब इस्तेमाल करें
- ✓जब किसी नियामक या एजेंसी की PDF डाउनलोड करने पर छोटी एरर फ़ाइल आए।
- ✓जब PDF स्क्रिप्ट या साइटों के बीच की पाबंदियों से सुरक्षित हो।
- ✓जब मुझे PDF से भरोसेमंद टेक्स्ट चाहिए, बैकअप विकल्पों के साथ।
Skill का लिंक
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-extraction-fallbacks-7d54a9/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“कृपया यह एजेंसी की PDF डाउनलोड करके उसका टेक्स्ट निकालिए। अगर फ़ाइल एरर पेज हो, तो मुझे बताइए और कोई और तरीका आज़माइए।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
AI फ़ाइल डाउनलोड करता है, लगभग एक किलोबाइट से छोटी या HTML जैसी दिखने वाली फ़ाइल को ठुकराता है, फिर pdftotext से टेक्स्ट निकालता है और क्रम से दूसरे टूल्स पर जाता है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
PDF Extraction Fallbacks
This skill provides a robust workflow for extracting text from PDFs when source documents may fail to download or extract due to JavaScript protection, CORS restrictions, or encoding issues.
When to Use
- Downloading regulatory documents from government/agency websites
- Extracting text from PDFs that may be JavaScript-protected
- Handling PDFs with potential CORS or encoding issues
- When you need reliable text extraction with guaranteed fallbacks
Core Workflow
Step 1: Download with Validation
# Download PDF and immediately validate
curl -L -o document.pdf "URL_HERE"
# Check file size (reject if < 1KB - likely error page)
FILE_SIZE=$(stat -f%z document.pdf 2>/dev/null || stat -c%s document.pdf 2>/dev/null)
if [ "$FILE_SIZE" -lt 1024 ]; then
echo "FAIL: File too small ($FILE_SIZE bytes) - likely error page"
# Log the actual content to diagnose
head -c 500 document.pdf
exit 1
fi
# Check for HTML/error content instead of PDF
if head -c 500 document.pdf | grep -qi "<!DOCTYPE html\|<html\|error\|access denied"; then
echo "FAIL: Downloaded HTML/error page instead of PDF"
exit 1
fi
Step 2: Sequential Extraction Fallbacks
Try extraction methods in order of reliability:
Fallback 1: pdftotext (poppler-utils)
if command -v pdftotext &> /dev/null; then
pdftotext -layout document.pdf output.txt 2>/dev/null
if [ -s output.txt ] && [ $(wc -c < output.txt) -gt 100 ]; then
echo "SUCCESS: pdftotext extraction"
exit 0
fi
fi
Fallback 2: PyMuPDF (fitz)
import fitz # PyMuPDF
def extract_with_pymupdf(pdf_path):
try:
doc = fitz.open(pdf_path)
text = ""
for page in doc:
text += page.get_text()
doc.close()
if len(text.strip()) > 100:
return text
return None
except Exception as e:
print(f"PyMuPDF failed: {e}")
return None
Fallback 3: pdfplumber
import pdfplumber
def extract_with_pdfplumber(pdf_path):
try:
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"
if len(text.strip()) > 100:
return text
return None
except Exception as e:
print(f"pdfplumber failed: {e}")
return None
Step 3: Content Sanity Check
After any extraction, validate the output:
def validate_extraction(text, min_chars=100, min_words=20):
"""Check if extracted text is meaningful content."""
if not text:
return False, "Empty extraction"
text = text.strip()
if len(text) < min_chars:
return False, f"Too short: {len(text)} chars"
words = text.split()
if len(words) < min_words:
return False, f"Too few words: {len(words)}"
# Check for error patterns
error_patterns = [
"access denied", "permission denied", "javascript required",
"failed to load", "cannot display", "corrupted"
]
text_lower = text.lower()
for pattern in error_patterns:
if pattern in text_lower[:500]: # Check beginning
return False, f"Error pattern detected: {pattern}"
return True, "Valid extraction"
Complete Python Implementation
import requests
import subprocess
import os
from pathlib import Path
def robust_pdf_extraction(url, output_path="extracted.txt", temp_pdf="temp.pdf"):
"""
Multi-fallback PDF extraction with validation at each step.
Returns (success, text_or_error)
"""
# Step 1: Download with validation
try:
response = requests.get(url, timeout=30, headers={
'User-Agent': 'Mozilla/5.0 (compatible; DocumentExtractor/1.0)'
})
response.raise_for_status()
except Exception as e:
return False, f"Download failed: {e}"
# Check response size
if len(response.content) < 1024:
return False, f"Downloaded content too small: {len(response.content)} bytes"
# Check for HTML error pages
if response.content[:500].lower().find(b'<html') != -1:
return False, "Downloaded HTML page instead of PDF"
# Save PDF
Path(temp_pdf).write_bytes(response.content)
# Step 2: Try extraction methods in order
extraction_methods = [
("pdftotext", extract_p
अक्सर पूछे जाने वाले सवाल
किस आकार को विफलता माना जाता है?
गाइड लगभग 1 किलोबाइट से छोटी फ़ाइलों को संभावित एरर पेज मानकर ठुकराती है।
HTML पेज कैसे पहचाना जाता है?
गाइड फ़ाइल की शुरुआत में HTML टैग या access denied जैसे शब्द खोजती है।
pdftotext के बाद क्या आज़माया जाता है?
गाइड क्रम से अगले फ़ॉलबैक तरीकों पर जाती है।
जानकारी
लेखक का मूल विवरण
Multi-fallback PDF extraction with sequential approaches and early failure detection
repo: HKUDS/AgentPilot
लोकप्रियता
- GitHub स्टार
- 7.8k
- रैंकिंग में स्थान
- #12924
- लाइसेंस
- 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 फ़ाइल तक किसकी पहुंच है, यह जांचने और बदलने देती है, और आपके अनुरोध के लिए सबसे छोटी अनुमति चुनती है।