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

pdf-verification

ما الذي تفعله

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

متى تستخدمها

  • ✓عندما تنتهي للتو مهمة إنشاء ملف PDF.
  • ✓عندما تتطلب المهمة عددًا محددًا من الصفحات.
  • ✓عندما أريد التأكد من أن الملف ليس فارغًا أو تالفًا قبل إنهاء المهمة.

رابط المهارة

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

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

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

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

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

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

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

“أحتاج إلى أن يكون الملف صفحتين. بعد إنشائه، من فضلك تحقق من عدد الصفحات وتأكد أنه يُفتح بشكل سليم.”

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

كيف تعمل

يثبّت الذكاء الاصطناعي PyPDF2 إذا لزم الأمر، ويشغّل فحصًا قصيرًا بـ run_shell يفتح الملف ويقارن عدد الصفحات بالهدف، ويبلغ بأي عدم تطابق.

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

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

PDF Verification Skill

Purpose

After generating PDF files, always verify page counts and file integrity programmatically before declaring task completion. This catches formatting issues, empty pages, and corrupted files early.

When to Use

  • After any PDF generation task
  • When specific page counts are required
  • Before marking a PDF-related task as complete

Verification Steps

1. Install PyPDF2 (if needed)

pip install PyPDF2

2. Verify Page Count and Integrity

Use run_shell to execute a Python verification script:

python -c "
from PyPDF2 import PdfReader
import sys

def verify_pdf(filepath, expected_pages=None):
    try:
        reader = PdfReader(filepath)
        actual_pages = len(reader.pages)
        print(f'✓ {filepath}: {actual_pages} pages')
        
        if expected_pages and actual_pages != expected_pages:
            print(f'✗ Page count mismatch: expected {expected_pages}, got {actual_pages}')
            return False
        
        # Check file is not empty/corrupted
        if actual_pages == 0:
            print(f'✗ Empty PDF: {filepath}')
            return False
        
        return True
    except Exception as e:
        print(f'✗ Error reading {filepath}: {e}')
        return False

# Verify each PDF
results = []
results.append(verify_pdf('output.pdf', expected_pages=2))
print(f'All checks passed: {all(results)}')
sys.exit(0 if all(results) else 1)
"

3. Verify Multiple PDFs

For tasks with multiple PDFs, verify each one:

python -c "
from PyPDF2 import PdfReader

pdfs = {
    'listings.pdf': 2,
    'map.pdf': 1,
    'summary.pdf': 1
}

all_passed = True
for filepath, expected in pdfs.items():
    try:
        reader = PdfReader(filepath)
        actual = len(reader.pages)
        status = '✓' if actual == expected else '✗'
        print(f'{status} {filepath}: {actual}/{expected} pages')
        if actual != expected:
            all_passed = False
    except Exception as e:
        print(f'✗ {filepath}: {e}')
        all_passed = False

print(f'Verification: {\"PASSED\" if all_passed else \"FAILED\"}')
"

4. Check File Size (Optional)

Add file size validation to catch empty or near-empty files:

python -c "
import os
from PyPDF2 import PdfReader

filepath = 'output.pdf'
min_size = 1000  # minimum bytes

file_size = os.path.getsize(filepath)
if file_size < min_size:
    print(f'✗ File too small: {file_size} bytes')
else:
    reader = PdfReader(filepath)
    print(f'✓ {filepath}: {len(reader.pages)} pages, {file_size} bytes')
"

Best Practices

  1. Verify immediately after generation - Don't wait until the end of the task
  2. Check all required PDFs - Verify each file meets specifications
  3. Fail fast - If verification fails, regenerate before proceeding
  4. Log results - Print verification results for debugging
  5. Set reasonable minimums - Use file size checks to catch empty outputs

Common Issues Caught

  • Wrong page counts (extra blank pages, missing content)
  • Corrupted or unreadable PDF files
  • Empty PDFs (0 pages)
  • Files that appear generated but contain no actual content

Example Task Completion Check

# Final verification before marking task complete
python -c "
from PyPDF2 import PdfReader
import sys

required = {'listings.pdf': 2, 'map.pdf': 1}
passed = True

for f, pages in required.items():
    try:
        actual = len(PdfReader(f).pages)
        if actual != pages:
            print(f'FAIL: {f} has {actual} pages, expected {pages}')
            passed = False
    except Exception as e:
        print(f'FAIL: Cannot read {f}: {e}')
        passed = False

if passed:
    print('SUCCESS: All PDFs verified')
    sys.exit(0)
else:
    sys.exit(1)
"
الأسئلة الشائعة

هل يكتشف الفحص ملفات PDF الفارغة؟

نعم، يبلغ السكربت عن ملف PDF بلا صفحات بأنه فارغ.

ماذا يحدث عند عدم التطابق؟

يطبع الفحص العدد المتوقع والعدد الفعلي، فتصبح المشكلة واضحة.

متى يُشغَّل الفحص؟

فور إنشاء ملف PDF وقبل تعليم المهمة مكتملة.

التفاصيل

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

Verify PDF page counts and file integrity programmatically using PyPDF2 after generation

repo: HKUDS/AgentPilot

الشعبية

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

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

0

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

التعليقات

  • …

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

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