Skillpedia
PDF وWord والعروض التقديمية7.8k · #12934

pdf-text-extraction-fallback

ما الذي تفعله

تشرح هذه المهارة كيفية استخراج نص PDF باستخدام pdftotext عندما تفشل أداة القراءة المدمجة. وهي مناسبة لمن يعمل بملفات PDF فيها صور أو تنسيق معقد.

متى تستخدمها

  • ✓عندما تُرجع قراءة PDF بيانات ثنائية أو صورية.
  • ✓عندما يحتوي PDF على صور مضمّنة أو تنسيق معقد.
  • ✓عندما أحتاج إلى نص قابل للقراءة من PDF لاستخدامه في مهمتي.

رابط المهارة

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

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-text-extraction-fallback/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“تعطيني أداة القراءة بيانات ثنائية لملف PDF الخاص بي. من فضلك تحقق من إعدادات الاستدعاء واستخرج النص بـ pdftotext.”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

يتأكد الذكاء الاصطناعي من أن استدعاء القراءة يستخدم اسم المعامل الصحيح، ويكتشف المخرجات الثنائية، ثم يشغّل pdftotext لطباعة النص على المخرج القياسي.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

PDF Text Extraction Fallback

When to Use This Skill

Use this skill when read_file with filetype="pdf" returns binary/image data instead of readable text content. This is a common issue with PDF files that contain embedded images or complex formatting.

Steps

1. Validate Parameters First

Before attempting extraction, ensure you're using the correct parameter name:

  • Use filetype (not file_type) for the read_file function
  • Incorrect parameter names can cause silent failures
# Correct
read_file(filetype="pdf", file_path="document.pdf")

# Incorrect - may fail silently
read_file(file_type="pdf", file_path="document.pdf")

2. Detect Binary Data Issue

After calling read_file, check if the result contains:

  • Garbled/binary characters
  • Image data representations (e.g., b'...' byte strings with non-text content)
  • Unreadable or corrupted-looking content

If yes, proceed with the pdftotext workaround.

3. Extract Text via pdftotext

Use run_shell to call pdftotext, which extracts text directly from PDF files:

# Extract text to stdout
result = run_shell(command="pdftotext /path/to/document.pdf -")
text_content = result.stdout

The - flag tells pdftotext to output to stdout instead of creating a file.

4. Handle Output and Errors

result = run_shell(command="pdftotext /path/to/document.pdf -")

if result.stderr:
    # Check for errors like "pdftotext not found"
    # May need to install poppler-utils
    pass

text_content = result.stdout
# text_content now contains the extracted text

Example Workflow

# Step 1: Try normal read with correct parameters
content = read_file(filetype="pdf", file_path="reference.pdf")

# Step 2: Check if content is readable
if not content or looks_like_binary(content):
    # Step 3: Fall back to pdftotext
    result = run_shell(command="pdftotext reference.pdf -")
    text_content = result.stdout
    
    # Step 4: Verify extraction succeeded
    if result.stderr:
        # Handle error (e.g., install pdftotext)
        pass

Installation Notes

pdftotext is part of the poppler-utils package:

  • Debian/Ubuntu: apt-get install poppler-utils
  • macOS: brew install poppler
  • Many Linux environments: Pre-installed

Alternative: Output to File

If stdout approach has issues, output to a temporary file:

run_shell(command="pdftotext /path/to/document.pdf /tmp/output.txt")
text_content = read_file(filetype="txt", file_path="/tmp/output.txt")

Best Practices

  1. Always validate the filetype parameter spelling before troubleshooting
  2. Check both stdout and stderr from pdftotext
  3. For multi-page PDFs, pdftotext preserves page breaks with form feeds
  4. This method works better for text-based PDFs than image-scanned PDFs
الأسئلة الشائعة

لماذا يهم اسم المعامل؟

يقول الدليل إن اسم معامل خاطئ قد يسبب إخفاقات صامتة.

كيف تُكتشف المخرجات الثنائية؟

يبحث الذكاء الاصطناعي عن محارف ثنائية أو علامات بيانات صورة في الناتج.

ماذا تفعل الشرطة في الأمر؟

تخبر pdftotext أن تطبع النص على الشاشة بدل كتابته في ملف.

التفاصيل

الوصف الأصلي من المؤلف

Extract text from PDFs using pdftotext when read_file returns binary data

repo: HKUDS/AgentPilot

الشعبية

نجوم GitHub
7.8k
الترتيب
#12934
الترخيص
MIT
آخر تحديث
1‏/11‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة