reportlab
Python library for programmatic PDF generation and creation. Use when user wants to generate PDFs from scratch, create invoices, reports, certificates, labels, or custom documents with precise control over layout, fonts, graphics, tables, and charts. Supports both low-level drawing (Canvas) and high-level documents (Platypus).
What this skill does
# ReportLab
## Overview
ReportLab is a powerful open-source Python library for creating PDF documents programmatically. Generate professional PDFs with precise control over layout, typography, graphics, tables, and charts. Perfect for automated report generation, invoices, certificates, and custom documents.
## When to Use This Skill
Activate when the user:
- Wants to generate PDF documents programmatically
- Needs to create invoices, reports, or receipts
- Asks to create certificates, labels, or forms
- Mentions ReportLab explicitly
- Wants custom PDF layouts with tables, charts, or graphics
- Needs to automate document generation
- Wants precise control over PDF layout and styling
## Installation
Check if ReportLab is installed:
```bash
python3 -c "import reportlab; print(reportlab.Version)"
```
If not installed:
```bash
pip3 install reportlab
```
For additional fonts and features:
```bash
pip3 install reportlab[renderPM,rlPyCairo]
```
## Two Approaches: Canvas vs Platypus
ReportLab provides two APIs:
**Canvas API (Low-Level)**
- Direct drawing on PDF pages
- Precise positioning with x, y coordinates
- Like painting on a canvas
- Best for: Simple documents, custom layouts, graphics-heavy PDFs
**Platypus API (High-Level)**
- Flowable document elements
- Automatic layout and pagination
- Easier for complex multi-page documents
- Best for: Reports, articles, documents with lots of text
## Canvas API (Low-Level Drawing)
### Basic Canvas Usage
```python
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter, A4
from reportlab.lib.units import inch
# Create PDF
c = canvas.Canvas("output.pdf", pagesize=letter)
width, height = letter
# Draw text
c.drawString(100, height - 100, "Hello, World!")
# Set font
c.setFont("Helvetica-Bold", 24)
c.drawString(100, height - 150, "Large Bold Text")
# Save PDF
c.save()
```
### Drawing Shapes and Lines
```python
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib import colors
c = canvas.Canvas("shapes.pdf", pagesize=letter)
width, height = letter
# Line
c.line(50, height - 50, width - 50, height - 50)
# Rectangle
c.rect(50, height - 200, 200, 100, stroke=1, fill=0)
# Filled rectangle with color
c.setFillColor(colors.lightblue)
c.setStrokeColor(colors.blue)
c.rect(300, height - 200, 200, 100, stroke=1, fill=1)
# Circle
c.circle(150, height - 350, 50, stroke=1, fill=0)
# Rounded rectangle
c.roundRect(300, height - 400, 200, 100, 10, stroke=1, fill=0)
c.save()
```
### Working with Text
```python
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib import colors
c = canvas.Canvas("text.pdf", pagesize=letter)
width, height = letter
# Different fonts and sizes
c.setFont("Helvetica", 12)
c.drawString(50, height - 50, "Helvetica 12pt")
c.setFont("Helvetica-Bold", 16)
c.drawString(50, height - 80, "Helvetica Bold 16pt")
c.setFont("Times-Roman", 14)
c.drawString(50, height - 110, "Times Roman 14pt")
# Colored text
c.setFillColor(colors.red)
c.drawString(50, height - 140, "Red text")
c.setFillColor(colors.blue)
c.drawString(50, height - 170, "Blue text")
# Text alignment
text = "Right-aligned text"
text_width = c.stringWidth(text, "Helvetica", 12)
c.setFont("Helvetica", 12)
c.setFillColor(colors.black)
c.drawString(width - text_width - 50, height - 200, text)
# Multi-line text with textobject
textobject = c.beginText(50, height - 250)
textobject.setFont("Helvetica", 12)
textobject.textLines("""This is multi-line text.
Each line will be rendered separately.
Great for paragraphs!""")
c.drawText(textobject)
c.save()
```
### Adding Images
```python
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.units import inch
c = canvas.Canvas("images.pdf", pagesize=letter)
width, height = letter
# Draw image
c.drawImage("logo.png", 50, height - 200, width=2*inch, height=1*inch)
# Image with preserved aspect ratio
c.drawImage("photo.jpg", 50, height - 400, width=3*inch, preserveAspectRatio=True)
c.save()
```
## Platypus API (High-Level Documents)
### Basic Document Structure
```python
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import inch
# Create document
doc = SimpleDocTemplate("document.pdf", pagesize=letter)
story = [] # Container for flowable elements
# Get styles
styles = getSampleStyleSheet()
# Add content
story.append(Paragraph("Document Title", styles['Title']))
story.append(Spacer(1, 0.2*inch))
story.append(Paragraph("This is a paragraph of text.", styles['Normal']))
story.append(Paragraph("This is another paragraph.", styles['Normal']))
# Build PDF
doc.build(story)
```
### Working with Paragraphs and Styles
```python
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.enums import TA_CENTER, TA_JUSTIFY
from reportlab.lib.units import inch
from reportlab.lib import colors
doc = SimpleDocTemplate("styled_doc.pdf", pagesize=letter)
story = []
styles = getSampleStyleSheet()
# Built-in styles
story.append(Paragraph("Title Style", styles['Title']))
story.append(Paragraph("Heading 1", styles['Heading1']))
story.append(Paragraph("Heading 2", styles['Heading2']))
story.append(Paragraph("Normal paragraph text.", styles['Normal']))
story.append(Spacer(1, 0.2*inch))
# Custom style
custom_style = ParagraphStyle(
'CustomStyle',
parent=styles['Normal'],
fontSize=14,
textColor=colors.blue,
alignment=TA_CENTER,
spaceAfter=10,
)
story.append(Paragraph("Centered blue text", custom_style))
# Justified paragraph
justified_style = ParagraphStyle(
'Justified',
parent=styles['Normal'],
alignment=TA_JUSTIFY,
)
long_text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " * 10
story.append(Paragraph(long_text, justified_style))
doc.build(story)
```
### Creating Tables
```python
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph
from reportlab.lib.pagesizes import letter
from reportlab.lib import colors
from reportlab.lib.styles import getSampleStyleSheet
doc = SimpleDocTemplate("table.pdf", pagesize=letter)
story = []
styles = getSampleStyleSheet()
story.append(Paragraph("Sales Report", styles['Title']))
# Table data
data = [
['Product', 'Q1', 'Q2', 'Q3', 'Q4'],
['Widget A', '$1,000', '$1,200', '$1,100', '$1,300'],
['Widget B', '$800', '$900', '$950', '$1,000'],
['Widget C', '$1,500', '$1,600', '$1,700', '$1,800'],
['Total', '$3,300', '$3,700', '$3,750', '$4,100'],
]
# Create table
table = Table(data)
# Style table
table.setStyle(TableStyle([
# Header row
('BACKGROUND', (0, 0), (-1, 0), colors.grey),
('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
('ALIGN', (0, 0), (-1, 0), 'CENTER'),
('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
('FONTSIZE', (0, 0), (-1, 0), 12),
('BOTTOMPADDING', (0, 0), (-1, 0), 12),
# Data rows
('BACKGROUND', (0, 1), (-1, -2), colors.beige),
('ALIGN', (1, 1), (-1, -1), 'RIGHT'),
('FONTNAME', (0, 1), (-1, -1), 'Helvetica'),
('FONTSIZE', (0, 1), (-1, -1), 10),
('GRID', (0, 0), (-1, -1), 1, colors.black),
# Total row
('BACKGROUND', (0, -1), (-1, -1), colors.lightgrey),
('FONTNAME', (0, -1), (-1, -1), 'Helvetica-Bold'),
]))
story.append(table)
doc.build(story)
```
### Adding Charts
```python
from reportlab.platypus import SimpleDocTemplate, Paragraph
from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.graphics.shapes import Drawing
from reportlab.graphics.charts.barcharts import VerticalBarChart
from reportlab.graphics.charts.piecharts import Pie
from reportlab.lib import colors
doc = SimpleDocTemplaRelated in Writing & Docs
jax-development
IncludedUse this skill when the user is writing, debugging, profiling, refactoring, reviewing, benchmarking, parallelising, exporting, or explaining JAX code, or when they mention JAX, jax.numpy, jit, grad, value_and_grad, vmap, scan, lax, random keys, pytrees, jax.Array, sharding, Mesh, PartitionSpec, NamedSharding, pmap, shard_map, Pallas, XLA, StableHLO, checkify, profiler, or the JAX repo. It helps turn NumPy or PyTorch-style code into pure functional JAX, fix tracer/control-flow/shape/PRNG bugs, remove recompiles and host-device syncs, choose transforms and sharding strategies, inspect jaxpr/lowering/IR, and benchmark compiled code correctly.
nature-article-writer
IncludedDrafts, rewrites, diagnostically critiques, and style-calibrates primary research manuscripts for Nature and Nature Portfolio journals. Use when the user wants a Nature-style title, summary paragraph or abstract, introduction, results, discussion, methods, figure legends, presubmission enquiry, cover letter, reviewer response, or when a scientific draft sounds generic, jargon-heavy, structurally weak, or AI-ish and needs precise, broad-reader-friendly prose without inventing data, analyses, or references. Best for primary research articles and letters rather than reviews or press releases unless explicitly adapting one.
deckrd
IncludedDocument-driven framework that derives requirements, specifications, implementation plans, and executable tasks from goals through structured AI dialogue. Use when user says "write requirements", "create spec", "plan implementation", "derive tasks", "structure this feature", "break down into tasks", or "document this module". Also use for reverse engineering existing code into docs (/deckrd rev). Do NOT use for direct code writing — use /deckrd-coder after tasks are generated. Do NOT use when the user only wants to run or fix existing code without planning.
clinical-decision-support
IncludedGenerate professional clinical decision support (CDS) documents for pharmaceutical and clinical research settings, including patient cohort analyses (biomarker-stratified with outcomes) and treatment recommendation reports (evidence-based guidelines with decision algorithms). Supports GRADE evidence grading, statistical analysis (hazard ratios, survival curves, waterfall plots), biomarker integration, and regulatory compliance. Outputs publication-ready LaTeX/PDF format optimized for drug development, clinical research, and evidence synthesis.
handling-sf-data
IncludedSalesforce data operations with 130-point scoring. Use this skill to create, update, delete, bulk import/export, generate test data, and clean up org records using sf CLI and anonymous Apex. TRIGGER when: user creates test data, performs bulk import/export, uses sf data CLI commands, needs data factory patterns for Apex tests, or needs to seed/clean records in a Salesforce org. DO NOT TRIGGER when: SOQL query writing only (use querying-soql), Apex test execution (use running-apex-tests), or metadata deployment (use deploying-metadata).
accelint-ac-to-playwright
IncludedConvert and validate acceptance criteria for Playwright test automation. Use when user asks to (1) review/evaluate/check if AC are ready for automation, (2) assess if AC can be converted as-is, (3) validate AC quality for Playwright, (4) turn AC into tests, (5) generate tests from acceptance criteria, (6) convert .md bullets or .feature Gherkin files to Playwright specs, (7) create test automation from requirements. Handles both bullet-style markdown and Gherkin syntax with JSON test plan generation and validation.