Registry / serialization / reportlab

reportlab

JSON →
library5.0.1pypypi✓ verified 28d ago

The ReportLab Toolkit is an open-source Python library for generating high-quality PDF documents and graphics. It provides both low-level APIs for precise control over PDF elements and a higher-level framework (PLATYPUS) for creating complex, structured documents with flowables like paragraphs and tables. Currently at version 4.4.10, ReportLab is actively maintained with regular updates and is widely used for dynamic, data-driven report generation, including by Wikipedia for its 'Download as PDF' feature.

pip install reportlab
INSTALL
IMPORT
SIG · REPORTLAB
R
reportlab
serializationpythonv5.0.1
Install
3.1s avg
Import
821ms
Disk
45MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v5.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.834s · 46.1MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 3.1s · import 0.808s · 47MB
45MB installed
● package 45MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SimpleDocTemplate
✓ from reportlab.platypus import SimpleDocTemplate
Paragraph
✓ from reportlab.platypus import Paragraph
getSampleStyleSheet
✓ from reportlab.lib.styles import getSampleStyleSheet
letter
✓ from reportlab.lib.pagesizes import letter
Canvas
✓ from reportlab.pdfgen import canvas
pdfgen
✓ from reportlab.pdfgen import canvas
✗ import reportlab.pdfgen
Submodules like `pdfgen` or `pdfbase` are often not directly available under `reportlab` namespace after a simple import `reportlab`. Always import specific classes or submodules directly, e.g., `from reportlab.pdfgen import canvas`.

This quickstart demonstrates how to create a basic PDF document using ReportLab's higher-level PLATYPUS framework. It initializes a `SimpleDocTemplate`, defines a 'story' (a list of 'flowables' like `Paragraph` and `Spacer`), applies standard styles, and then builds the PDF.

from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer from reportlab.lib.styles import getSampleStyleSheet from reportlab.lib.pagesizes import letter def create_pdf(filename="hello_reportlab.pdf"): doc = SimpleDocTemplate(filename, pagesize=letter) styles = getSampleStyleSheet() story = [] # Add a title story.append(Paragraph("Hello, ReportLab!", styles['h1'])) story.append(Spacer(1, 0.2 * 25.4)) # Add a paragraph long_text = "This is an example of a simple PDF document generated using the ReportLab Toolkit. It demonstrates how to use `SimpleDocTemplate` and `Paragraph` for basic text content. ReportLab provides extensive capabilities for layouts, tables, images, and graphics." story.append(Paragraph(long_text, styles['Normal'])) # Build the PDF document doc.build(story) print(f"PDF created: {filename}") if __name__ == "__main__": create_pdf()
reportlab --version
Debug
Known issues
breakingReportLab 3.0 (released 2014) introduced significant internal rewrites for Python 3 compatibility and consistent Unicode/bytes handling. While API changes were minimized, older code might encounter unexpected behavior related to string encoding.
fix
Review and update code for Python 3 compatibility, particularly regarding string types. Refer to ReportLab's change logs for detailed transitions.
affects: <3.0
breakingReusing flowable objects (e.g., `Paragraph`, `Table`) in multiple document builds or pages without re-instantiating them can lead to `LayoutError` exceptions. ReportLab modifies these objects in place during the layout process, which is not reset for subsequent uses.
fix
Always create new instances of flowable objects for each use, especially if generating multiple documents or repeating elements across different sections/pages. For example, `story.append(Paragraph('Text', styles['Normal']))` should be done for each paragraph, not defining `my_paragraph = Paragraph(...)` once and appending it multiple times.
affects: All versions
gotchaThe default coordinate system in ReportLab's `canvas` module has its origin (0,0) at the bottom-left corner of the page. This is different from many other graphics libraries where the origin is top-left, and can lead to incorrect positioning if not accounted for.
fix
Always remember that y-coordinates increase upwards. Adjust calculations accordingly, or use helper functions/classes that abstract this if needed.
affects: All versions
gotchaOptional C extensions (e.g., `rl_accel`, `rl_renderpm`) are crucial for optimal performance, especially with bitmap image processing and complex graphics. If these are not installed (often requiring a C compiler during `pip install`), ReportLab will fall back to slower pure-Python implementations or lack certain features.
fix
Ensure that development tools including a C compiler (e.g., Build Tools for Visual Studio on Windows, Xcode Command Line Tools on macOS, `build-essential` on Linux) are installed before running `pip install reportlab` to allow compilation of optional C extensions. Verify installation by checking for performance or missing features.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'reportlab'
The ReportLab library is not installed in the current Python environment or is not accessible within the project's interpreter.
fix
Install the ReportLab library using pip: `pip install reportlab`
AttributeError: 'module' object has no attribute 'canvas'
The `canvas` class is imported incorrectly, typically by importing the `reportlab.pdfgen` module instead of importing `canvas` directly from it.
fix
Import the `canvas` class explicitly: `from reportlab.pdfgen import canvas`
TypeError: __init__() missing 1 required positional argument: 'filename'
The `canvas.Canvas` constructor was called without providing the mandatory `filename` argument, which specifies the name of the output PDF file.
fix
Provide a string argument for the output PDF filename when initializing Canvas, e.g., `c = canvas.Canvas("my_document.pdf")`
reportlab.pdfbase._fontdata.ReportLabFontError: Can't register font, not a TTF file?
An attempt was made to register a font file that is either not a valid TrueType Font (TTF) file, is corrupted, or the file path provided to `pdfmetrics.registerFont` is incorrect.
fix
Ensure the font file is a valid TTF and verify that the file path provided to `pdfmetrics.registerFont` is correct and accessible.
reportlab.lib.utils.ImageReader.get==>Failed to find image data in PNG file
ReportLab was unable to read the image file, often because the file path is incorrect, the image file is corrupted, or the required `Pillow` library for advanced image processing is not installed.
fix
Verify the image file path is correct, ensure the image file is valid and supported, and install `Pillow` if it's missing: `pip install Pillow`
Upgrade
Version history
5.0.1latest on PyPI · released Aug 20, 2026
Audit
Dependencies
charset-normalizerrequiredRequired for character set detection.
PillowrequiredRequired for bitmap image handling within PDFs.
rl_acceloptionalOptional C extensions for improved performance.
rl_renderpmoptionalOptional C extensions for advanced graphics rendering (e.g., bitmap images).
Agent activity
15 hits · last 30 days
node
12
Amazon
1
Resources