---
name: reportlab-styles-9935d7dee185
description: Use reportlab's pre-defined styles from getSampleStyleSheet() correctly
---

# ReportLab Pre-Defined Styles Reference

## Overview

ReportLab's `reportlab.lib.styles.getSampleStyleSheet()` provides a collection of pre-defined paragraph styles. Use these existing styles rather than redefining them to avoid `KeyError` exceptions.

## Available Pre-Defined Styles

The standard stylesheet includes these commonly-used styles:

| Style Name | Purpose |
|------------|---------|
| `Normal` | Default body text |
| `Title` | Document title (large, bold) |
| `Heading1` | Level 1 section heading |
| `Heading2` | Level 2 section heading |
| `Heading3` | Level 3 section heading |
| `Heading4` | Level 4 section heading |
| `Heading5` | Level 5 section heading |
| `Heading6` | Level 6 section heading |
| `Bullet` | Bulleted list items |
| `Definition` | Definition list terms |
| `Italic` | Italicized text |
| `Code` | Monospace code text |

## Correct Usage Pattern

```python
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.platypus import Paragraph

# Get the stylesheet
styles = getSampleStyleSheet()

# Use existing styles directly (CORRECT)
title = Paragraph("My Document Title", styles['Title'])
heading = Paragraph("Section Header", styles['Heading1'])
body = Paragraph("Regular text content", styles['Normal'])
```

## Common Mistake to Avoid

```python
# WRONG - Don't redefine existing style names
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle

styles = getSampleStyleSheet()

# This will cause KeyError when you try to use 'Title' later
styles.add(ParagraphStyle(
    name='Title',  # Overwrites the pre-defined 'Title' style
    fontSize=24,
    # ... incomplete definition
))

# Later code expecting the full 'Title' style will fail
paragraph = Paragraph("Title Text", styles['Title'])  # KeyError!
```

## Best Practices

1. **Use existing styles as-is** when they meet your needs
2. **Create new style names** for custom styles (e.g., `MyCustomTitle`, `CustomHeading`)
3. **Base custom styles on existing ones** when you need modifications:

```python
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle

styles = getSampleStyleSheet()

# Create a NEW style with a unique name
custom_title = ParagraphStyle(
    name='CustomTitle',  # Unique name, doesn't conflict
    parent=styles['Title'],  # Base it on existing Title
    fontSize=28,
    spaceAfter=30
)
styles.add(custom_title)

# Now both styles are available
styles['Title']       # Original pre-defined style
styles['CustomTitle'] # Your custom variant
```

## Quick Reference Checklist

- [ ] Import `getSampleStyleSheet()` from `reportlab.lib.styles`
- [ ] Call `styles = getSampleStyleSheet()` once at the start
- [ ] Access styles via `styles['StyleName']` (case-sensitive)
- [ ] Do NOT add styles with names that already exist in the stylesheet
- [ ] Use unique names for any custom styles you create
- [ ] Common available styles: `Normal`, `Title`, `Heading1-6`, `Bullet`, `Code`, `Italic`

---
Source attribution: zhanghong3721
Original project: https://github.com/zhanghong3721/kimiclaw/blob/a56eb2c0cba8a30e497cee4f4a4c79aa1f76aff0/openspace/gdpval_bench/skills/reportlab-styles/SKILL.md
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Dave AI.

## Upstream license notice

MIT License

Copyright (c) 2026 ✨Data Intelligence Lab@HKU✨

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Dave AI resource metadata

Creator / publisher: zhanghong3721
Original project: https://github.com/zhanghong3721/kimiclaw/blob/a56eb2c0cba8a30e497cee4f4a4c79aa1f76aff0/openspace/gdpval_bench/skills/reportlab-styles/SKILL.md
Attribution basis: Source repository record

Fields of work: Development & Engineering
Roles: Backend Developer, Frontend Developer, Full-Stack Developer
Specialties: Backend, Cross Platform
Tools: Reportlab
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 27a2a995dc8e98f7df0f1c115b82a469d78155e56941cc24198b53f15fe400c1
