मुख्य सामग्री पर जाएँ
Skillpedia
PDF, Word और स्लाइड7.8k · #12918

pdf-extract-ordered-fallback

यह क्या करती है

यह स्किल वेब स्रोतों से PDF टेक्स्ट लेने के लिए टूल इस्तेमाल का स्पष्ट क्रम तय करती है। यह उन लोगों के लिए है जिनके PDF काम रीडायरेक्ट, खराब फ़ाइलों या गायब टूल्स से विफल होते हैं।

कब इस्तेमाल करें

  • ✓जब PDF लिंक रीडायरेक्ट हो या फ़ाइल के बजाय वेब पेज लौटाए।
  • ✓जब मुझे पढ़ने से पहले पक्का करना है कि PDF असली फ़ाइल है।
  • ✓जब मुझे तरीकों का तय क्रम चाहिए, ताकि AI यादृच्छिक टूल न आज़माए।

Skill का लिंक

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-download-extract-fallback-enhanced/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-download-extract-fallback-enhanced/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“इस लिंक से PDF डाउनलोड कीजिए और उसका टेक्स्ट निकालिए। टूल्स का तय क्रम मानिए और बताइए कि कौन सा काम आया।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

AI ब्राउज़र जैसे अनुरोध से फ़ाइल डाउनलोड करता है, file कमांड से उसका प्रकार जाँचता है, फिर सरल रीड, pdftotext और PyMuPDF को क्रम से आज़माता है, जब तक टेक्स्ट न निकले।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

PDF Download and Extract with Ordered Fallback

This skill provides a robust workflow for acquiring PDF documents from web sources and extracting their text content, with a clearly ordered sequence of tool invocations to maximize success rate.

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 a严格 ordered fallback sequence that prioritizes shell-based tools over Python sandbox execution.

Ordered Tool Chain Summary

Step Tool Method Priority
0 read_file Direct PDF text extraction First attempt
1 run_shell pdftotext command Primary fallback (if Step 0 returns binary/fails)
2 execute_code_sandbox PyMuPDF Python library Secondary fallback (if Step 1 fails)
3 Domain knowledge Manual content generation Last resort

Key principle: Always try shell tools (run_shell) before Python sandbox (execute_code_sandbox) when both are viable options. Shell execution is more reliable in constrained environments.

Step-by-Step Instructions

Step 0: Initial Extraction Attempt with read_file Tool

First, attempt to extract PDF text using the read_file tool. This is the simplest approach and handles many PDFs correctly:

read_file filetype="pdf" file_path="path/to/document.pdf"

Expected outcomes:

  • Success: Returns extracted text content - proceed to use this directly
  • Binary/Image data returned: The tool failed to extract text; file content is raw binary or image data
    • Immediate action: Proceed to Step 1 (run_shell with pdftotext)
  • Error returned: Tool failed entirely; proceed to Step 1 (run_shell with pdftotext)

Critical: If read_file returns binary data (PNG/JPEG headers, raw PDF bytes), do NOT attempt to parse it manually. Immediately switch to shell-based pdftotext.

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 Shell Extraction with pdftotext via run_shell

This step takes priority over Python-based extraction. If Step 0 failed or if you're working with a newly downloaded PDF, use run_shell with pdftotext before attempting any Python libraries:

pdftotext downloaded.pdf extracted.txt

Execute via run_shell:

run_shell command="pdftotext downloaded.pdf extracted.txt"

If pdftotext is not available, install it first:

# Debian/Ubuntu
apt-get update && apt-get install -y poppler-utils

# macOS  
brew install poppler

# RHEL/CentOS
yum install -y poppler-utils

Why shell-first? Shell-based pdftotext is more reliable, faster, and avoids sandbox execution issues that can affect Python code execution in constrained environments.

Step 4: Secondary Python Fallback with PyMuPDF via execute_code_sandbox

Only if run_shell with pdftotext fails or is unavailable, fall back to Python's PyMuPDF library via execute_code_sandbox:

import fitz  # PyMuPDF

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)

Execute within execute_code_sandbox:

execute_code_sandbox code="<Python code above>"

Install if needed:

pip install pymupdf

Note: Some environments may experience execute_code_sandbox failures (unknown errors). This is why shell-based extraction (Step 3) must be attempted first.

Step 5: Graceful Degradation to Domain Knowledge

If the PDF cannot be accessed or extracted after all attempts:

  1. Document the failure mode (network issue, corrupted file, access denied, etc.)
  2. Extract any partia
अक्सर पूछे जाने वाले सवाल

फ़ाइल का प्रकार कैसे जाँचा जाता है?

file कमांड बताता है कि डाउनलोड PDF है या कोई एरर पेज।

पार्स करने से पहले क्यों जाँचें?

रीडायरेक्ट से PDF की जगह HTML पेज आ सकता है, जिससे निकासी विफल होगी।

आखिरी विकल्प क्या है?

गाइड कहती है कि जब निकासी का कोई तरीका काम न करे, तो डोमेन ज्ञान से सामग्री बनाएँ।

जानकारी

लेखक का मूल विवरण

PDF extraction with ordered tool chain: read_file, then run_shell/pdftotext, then execute_code_sandbox/PyMuPDF

repo: HKUDS/AgentPilot

लोकप्रियता

GitHub स्टार
7.8k
रैंकिंग में स्थान
#12918
लाइसेंस
MIT
अपडेट की गई
1/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills