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

pdf-read-file-fallback

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

यह स्किल उन PDF के लिए बैकअप है, जिन्हें अंतर्निहित रीडर इमेज या बाइनरी डेटा के रूप में लौटाता है। यह उन लोगों के लिए है जिन्हें PDF के अंदर के शब्द चाहिए, जिन्हें AI सामान्य तरीके से नहीं पढ़ सकता।

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

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

Skill का लिंक

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-read-file-fallback/SKILL.md

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

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

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

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

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

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

“AI मेरी PDF से सिर्फ़ बाइनरी डेटा पा रहा है। कृपया कमांड-लाइन टूल से टेक्स्ट निकालिए।”

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

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

AI पहले सामान्य फ़ाइल रीड आज़माता है, जाँचता है कि नतीजा उपयोगी है या नहीं, और न होने पर layout विकल्प के साथ pdftotext चलाकर टेक्स्ट लेता है।

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

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

PDF Text Extraction Fallback

When to Use

Use this pattern when read_file with filetype="pdf" returns binary image data instead of extractable text content. This commonly occurs with PDFs that contain scanned images or complex formatting.

Steps

1. Attempt Primary Extraction

First, try using read_file:

result = read_file(file_path="document.pdf", filetype="pdf")

Important: Use filetype (not file_type) - incorrect parameter naming will cause execution failures.

2. Detect Binary/Image Data

Check if the result contains unusable content:

# Indicators of binary/image data:
# - Contains null bytes: '\x00'
# - Very short or empty
# - Contains image markers (PNG/JPEG headers)
# - Unreadable character sequences

if not result or len(result) < 50 or '\x00' in str(result):
    # Proceed to fallback

3. Use pdftotext via run_shell

Extract text using the pdftotext command-line tool:

shell_result = run_shell(command="pdftotext -layout document.pdf -")
text_content = shell_result.stdout

The - flag outputs to stdout for easy capture. The -layout flag preserves original formatting.

4. Handle pdftotext Unavailable

If pdftotext is not installed, try Python-based extraction:

result = execute_code_sandbox(code="""
import pdfplumber
text = ''
with pdfplumber.open('document.pdf') as pdf:
    for page in pdf.pages:
        extracted = page.extract_text()
        if extracted:
            text += extracted + '\\n'
print(text)
""")

Complete Example

file_path = "report.pdf"

# Primary attempt
result = read_file(file_path=file_path, filetype="pdf")

# Validate and fallback if needed
if not result or len(str(result)) < 100 or '\x00' in str(result):
    # Fallback to pdftotext
    shell_result = run_shell(command=f"pdftotext -layout {file_path} -")
    text_content = shell_result.stdout
    
    # If pdftotext fails, try Python extraction
    if not text_content or len(text_content) < 50:
        code_result = execute_code_sandbox(code=f"""
import pdfplumber
text = ''
with pdfplumber.open('{file_path}') as pdf:
    for page in pdf.pages:
        extracted = page.extract_text()
        if extracted:
            text += extracted + '\\n'
print(text)
""")
        text_content = code_result

Notes

  • pdftotext is part of the poppler-utils package on most Linux systems
  • For scanned/image-only PDFs, consider OCR tools (tesseract) instead
  • Always validate parameter names against tool documentation (filetype vs file_type)
अक्सर पूछे जाने वाले सवाल

layout विकल्प क्या करता है?

यह पेज की मूल दूरी और संरचना जितना संभव हो उतना बनाए रखता है।

अगर pdftotext गायब हो तो?

गाइड बैकअप के रूप में pdfplumber जैसी Python लाइब्रेरी सुझाती है।

बाइनरी आउटपुट कैसे पहचाना जाता है?

गाइड null बाइट, बहुत छोटे नतीजे या इमेज हेडर जैसे संकेत बताती है।

जानकारी

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

Extract text from PDFs using pdftotext when read_file returns binary data

repo: HKUDS/AgentPilot

लोकप्रियता

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

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

0

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

कमेंट

  • …

इस repository की और skills

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