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

direct-reportlab-pdf-generation

ما الذي تفعله

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

متى تستخدمها

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

رابط المهارة

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

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

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

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

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

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

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

“أريد تقرير PDF من عدة صفحات فيه صفحة عنوان وجداول وأقسام، مصنوع بـ ReportLab. هل تستطيع بناءه؟”

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

كيف تعمل

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

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

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

Direct ReportLab PDF Generation via run_shell

When to Use This Skill

Use this pattern when:

  • You need to create a complex, multi-page PDF document with structured content
  • Delegating PDF generation to shell_agent fails or produces unreliable results
  • You need fine-grained control over PDF layout, styling, and pagination

Core Technique

Instead of asking shell_agent to handle PDF creation, write inline Python code using the reportlab library and execute it directly via run_shell. This gives you deterministic control over the document structure.

Step-by-Step Instructions

Step 1: Prepare Your PDF Content

Organize your content into logical sections that will become pages or page groups:

  • Title page
  • Table of contents (optional)
  • Main content sections
  • Appendices or references

Step 2: Write the ReportLab Python Script

Create a Python script that uses these key reportlab components:

from reportlab.lib import colors
from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle, PageBreak, Image
from reportlab.lib.enums import TA_CENTER, TA_LEFT, TA_JUSTIFY

def create_pdf(filename, content_data):
    doc = SimpleDocTemplate(filename, pagesize=letter,
                           rightMargin=72, leftMargin=72,
                           topMargin=72, bottomMargin=72)
    
    story = []
    styles = getSampleStyleSheet()
    
    # Custom styles
    title_style = ParagraphStyle(
        'CustomTitle',
        parent=styles['Heading1'],
        fontSize=24,
        textColor=colors.HexColor('#1a1a1a'),
        spaceAfter=30,
        alignment=TA_CENTER
    )
    
    heading_style = ParagraphStyle(
        'CustomHeading',
        parent=styles['Heading2'],
        fontSize=16,
        textColor=colors.HexColor('#2c3e50'),
        spaceBefore=20,
        spaceAfter=12
    )
    
    body_style = ParagraphStyle(
        'CustomBody',
        parent=styles['Normal'],
        fontSize=11,
        leading=16,
        alignment=TA_JUSTIFY
    )
    
    # Build document content
    for section in content_data:
        if section['type'] == 'title':
            story.append(Paragraph(section['text'], title_style))
        elif section['type'] == 'heading':
            story.append(Paragraph(section['text'], heading_style))
        elif section['type'] == 'paragraph':
            story.append(Paragraph(section['text'], body_style))
            story.append(Spacer(1, 12))
        elif section['type'] == 'table':
            table = Table(section['data'], colWidths=section.get('col_widths'))
            table.setStyle(TableStyle([
                ('BACKGROUND', (0, 0), (-1, 0), colors.grey),
                ('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
                ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
                ('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
                ('FONTSIZE', (0, 0), (-1, 0), 12),
                ('BOTTOMPADDING', (0, 0), (-1, 0), 12),
                ('BACKGROUND', (0, 1), (-1, -1), colors.beige),
                ('GRID', (0, 0), (-1, -1), 1, colors.black),
            ]))
            story.append(table)
            story.append(Spacer(1, 20))
        elif section['type'] == 'pagebreak':
            story.append(PageBreak())
    
    doc.build(story)

Step 3: Execute via run_shell

Run the Python script directly using run_shell:

python3 << 'EOF'
# Your complete reportlab script here
from reportlab.lib import colors
from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle, PageBreak

# ... rest of your script
EOF

Or save to a file and execute:

cat > generate_pdf.py << 'SCRIPT'
# Your complete script
SCRIPT

python3 generate_pdf.py

Step 4: Handle Complex Content

For lengthy documents, structure content as a data structure:

document_sections = [
    {'type': 'title', 'text': 'Document Title'},
    {'type': 'pagebreak'},
    {'type': 'heading', 'text': 'Section 1'},
    {'type': 'paragraph', 'text': 'Content here...'},
    {'type': 'heading', 'text': 'Section 2'},
    {'type': 'table', 'data': [['Header1', 'Header2'], ['Row1-Col1', 'Row1-Col2']]},
    {'type': 'pagebreak'},
    # 
الأسئلة الشائعة

ما هي ReportLab؟

مكتبة Python لإنشاء ملفات PDF تحتوي على نصوص وجداول وصور.

هل أحتاج إلى معرفة Python؟

تتضمن المهارة شيفرة أمثلة، لكن تشغيلها يتطلب تثبيت Python ومكتبة ReportLab.

هل يُضمَّن فهرس المحتويات؟

تُدرج خطة المحتوى فهرس المحتويات بوصفه اختيارياً.

التفاصيل

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

Generate complex multi-page PDFs by running reportlab Python code directly via run_shell when shell_agent fails on document creation

repo: HKUDS/AgentPilot

الشعبية

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

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

0

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

التعليقات

  • …

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

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