pdf-download-extract-fallback
यह क्या करती है
यह स्किल वेब पते से PDF लेने और उसका टेक्स्ट पढ़ने को कवर करती है, कई फ़ॉलबैक रास्तों के साथ। यह उन लोगों के लिए है जिन्हें ऑनलाइन PDF की सामग्री चाहिए, जो हमेशा साफ़ तरह से डाउनलोड नहीं होती।
कब इस्तेमाल करें
- ✓जब PDF लिंक रीडायरेक्ट से सुरक्षित हो या स्वचालित अनुरोध रोकता हो।
- ✓जब डाउनलोड की गई फ़ाइल खराब हो या एरर पेज हो सकती हो।
- ✓जब कंप्यूटर पर pdftotext या कोई दूसरा टूल गायब हो।
Skill का लिंक
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-download-extract-fallback/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“इस वेब पते की PDF का टेक्स्ट चाहिए। अगर डाउनलोड विफल हो या फ़ाइल खराब हो, तो दूसरा तरीका आज़माइए।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
AI ब्राउज़र जैसे अनुरोध से फ़ाइल डाउनलोड करता है, file कमांड से पुष्टि करता है कि वह PDF है, और फिर pdftotext या Python लाइब्रेरी से टेक्स्ट निकालता है, विफल होने पर फ़ॉलबैक के साथ।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
PDF Download and Extract with Fallback
This skill provides a robust workflow for acquiring PDF documents from web sources and extracting their text content, with multiple fallback mechanisms to handle various failure modes.
Overview
When working with PDFs from web sources, encounters with JavaScript redirects, corrupted files, missing tools, or inaccessible content are common. This workflow ensures maximum success rate through progressive fallback strategies.
Step-by-Step Instructions
Step 1: Download PDF with Browser User-Agent
Many PDF hosting sites use JavaScript-based redirects or block automated requests. Use curl with a realistic browser user-agent:
curl -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" -o output.pdf "URL_HERE"
Key flags:
-L: Follow redirects-A: Set user-agent header to mimic a real browser-o: Specify output filename
Step 2: Verify File Type Before Parsing
Always validate the downloaded file is actually a PDF before attempting extraction:
file output.pdf
Expected output should contain "PDF document". If not:
- The URL may have redirected to an HTML error page
- The file may be corrupted
- Access may be blocked
Step 3: Primary Extraction with pdftotext
First attempt extraction using the standard pdftotext utility (part of poppler-utils):
pdftotext output.pdf output.txt
If pdftotext is not available, install it:
# Debian/Ubuntu
apt-get update && apt-get install -y poppler-utils
# macOS
brew install poppler
# RHEL/CentOS
yum install -y poppler-utils
Step 4: Fallback to PyMuPDF (fitz)
If pdftotext fails or produces poor results, use Python's PyMuPDF library:
import fitz # PyMuPDF
doc = fitz.open("output.pdf")
text = ""
for page in doc:
text += page.get_text()
doc.close()
with open("output.txt", "w") as f:
f.write(text)
Install if needed:
pip install pymupdf
Step 5: Graceful Degradation to Domain Knowledge
If the PDF cannot be accessed or extracted after all attempts:
- Document the failure mode (network issue, corrupted file, access denied, etc.)
- Extract any partial content that was successfully retrieved
- Supplement missing content from established domain knowledge
- Clearly mark which portions are from source vs. generated from knowledge
- Provide citations for any claimed requirements or specifications
Example degradation note:
NOTE: Source document [URL] was inaccessible due to [reason].
Content below combines partial extraction with established domain knowledge
for [topic]. Verify against official sources when available.
Complete Workflow Script
#!/bin/bash
# pdf-extract-workflow.sh
# pdf-extract-workflow.sh - Handles both URL downloads and local files
INPUT="$1"
OUTPUT_PDF="downloaded.pdf"
OUTPUT_TXT="extracted.txt"
if [[ "$INPUT" =~ ^https?:// ]]; then
# Mode A: URL download
PDF_URL="$INPUT"
echo "Downloading PDF from URL..."
curl -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" -o "$OUTPUT_PDF" "$PDF_URL"
else
# Mode B: Local file
if [ ! -f "$INPUT" ]; then
echo "ERROR: Local file not found: $INPUT"
exit 1
fi
OUTPUT_PDF="$INPUT"
echo "Using local file: $INPUT"
fi
# Step 2: Verify file type
echo "Verifying file type..."
if ! file "$OUTPUT_PDF" | grep -q "PDF document"; then
echo "WARNING: Downloaded file is not a valid PDF"
echo "Attempting fallback extraction anyway..."
fi
# Step 3: Try pdftotext
echo "Attempting pdftotext extraction..."
if command -v pdftotext &> /dev/null; then
if pdftotext "$OUTPUT_PDF" "$OUTPUT_TXT" 2>/dev/null; then
echo "Extraction successful with pdftotext"
exit 0
fi
fi
# Step 4: Fallback to PyMuPDF
echo "Falling back to PyMuPDF..."
python3 << 'PYTHON_SCRIPT'
import fitz
import sys
try:
doc = fitz.open("downloaded.pdf")
text = ""
for page in doc:
text += page.get_text()
doc.close()
with open("extracted.txt", "w") as f:
f.write(text)
print("Extraction successful with PyMuPDF")
sys.exit(0)
except Exception as e:
print(f"PyMuPDF failed: {e}")
sys.exit(1)
PYTHON_SCRIPT
# Step 5: Handle complete failure
# Step 5: Handle complete failure (domain knowledge fallback)
if [ $? -ne 0 ]; then
echo "ERROR: All extraction methods failed."
echo "ACTION: Gener
अक्सर पूछे जाने वाले सवाल
ब्राउज़र जैसे अनुरोध से क्या होता है?
यह तब मदद करता है जब साइट स्वचालित अनुरोध रोकती है या रीडायरेक्ट इस्तेमाल करती है।
खराब डाउनलोड कैसे पहचानें?
file कमांड बताता है कि नतीजा PDF दस्तावेज़ है या HTML पेज जैसी कोई और चीज़।
अगर pdftotext गायब हो तो?
गाइड निकासी चरण के लिए Python लाइब्रेरी का फ़ॉलबैक देती है।
जानकारी
लेखक का मूल विवरण
Multi-step PDF download and text extraction with progressive fallback strategies
repo: HKUDS/AgentPilot
लोकप्रियता
- GitHub स्टार
- 7.8k
- रैंकिंग में स्थान
- #12919
- लाइसेंस
- 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 फ़ाइल तक किसकी पहुंच है, यह जांचने और बदलने देती है, और आपके अनुरोध के लिए सबसे छोटी अनुमति चुनती है।