一键导入
direct-reportlab-pdf-generation
Generate complex multi-page PDFs by running reportlab Python code directly via run_shell when shell_agent fails on document creation
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Generate complex multi-page PDFs by running reportlab Python code directly via run_shell when shell_agent fails on document creation
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Delegate tasks to OpenSpace — a full-stack autonomous worker for coding, DevOps, web research, and desktop automation, backed by an extensive MCP tool and skill library. Skills auto-improve through use, reducing token consumption over time. A cloud community lets agents share and collectively evolve reusable skills.
Incremental audio production with duration mismatch handling, adaptive stem extension, and pre-mix alignment verification
Audio production with diagnostic analysis, timecode parsing from documents, and verified export workflow
Incremental audio production with duration alignment handling, per-stem verification, and adaptive extension strategies
Step-by-step audio production with per-stem verification, timing alignment, and incremental quality gates
End-to-end audio production workflow with stems, effects, archiving, and verification
| name | direct-reportlab-pdf-generation |
| description | Generate complex multi-page PDFs by running reportlab Python code directly via run_shell when shell_agent fails on document creation |
Use this pattern when:
shell_agent fails or produces unreliable resultsInstead 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.
Organize your content into logical sections that will become pages or page groups:
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)
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
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'},
# Continue for all sections
]
Check that the PDF was created successfully:
ls -la your_document.pdf
# Optionally check page count
pdfinfo your_document.pdf 2>/dev/null || echo "PDF created, pdfinfo not available"
Use PageBreak() between major sections to ensure clean pagination.
Structure tabular data as nested lists:
table_data = [
['Column 1', 'Column 2', 'Column 3'],
['Value 1', 'Value 2', 'Value 3'],
['Value 4', 'Value 5', 'Value 6'],
]
Create custom ParagraphStyle objects for consistent formatting across sections.
ReportLab automatically handles text wrapping. For very long content, consider breaking into multiple paragraphs.
| Issue | Solution |
|---|---|
| Import errors | Ensure reportlab is installed: pip install reportlab |
| Layout issues | Adjust margins in SimpleDocTemplate constructor |
| Text overflow | Use Spacer elements to add vertical space |
| Table width problems | Set explicit colWidths parameter |
| Page breaks in wrong places | Insert PageBreak() explicitly before new sections |