{"id":944,"library":"reportlab","title":"ReportLab Toolkit","description":"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.","status":"active","version":"4.4.10","language":"python","source_language":"en","source_url":"https://www.reportlab.com/","tags":["pdf","document generation","graphics","reporting","platypus"],"install":[{"cmd":"pip install reportlab","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for character set detection.","package":"charset-normalizer","optional":false},{"reason":"Required for bitmap image handling within PDFs.","package":"Pillow","optional":false},{"reason":"Optional C extensions for improved performance.","package":"rl_accel","optional":true},{"reason":"Optional C extensions for advanced graphics rendering (e.g., bitmap images).","package":"rl_renderpm","optional":true}],"imports":[{"symbol":"SimpleDocTemplate","correct":"from reportlab.platypus import SimpleDocTemplate"},{"symbol":"Paragraph","correct":"from reportlab.platypus import Paragraph"},{"symbol":"getSampleStyleSheet","correct":"from reportlab.lib.styles import getSampleStyleSheet"},{"symbol":"letter","correct":"from reportlab.lib.pagesizes import letter"},{"symbol":"Canvas","correct":"from reportlab.pdfgen import canvas"},{"note":"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`.","wrong":"import reportlab.pdfgen","symbol":"pdfgen","correct":"from reportlab.pdfgen import canvas"}],"quickstart":{"code":"from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer\nfrom reportlab.lib.styles import getSampleStyleSheet\nfrom reportlab.lib.pagesizes import letter\n\ndef create_pdf(filename=\"hello_reportlab.pdf\"): \n    doc = SimpleDocTemplate(filename, pagesize=letter)\n    styles = getSampleStyleSheet()\n    story = []\n\n    # Add a title\n    story.append(Paragraph(\"Hello, ReportLab!\", styles['h1']))\n    story.append(Spacer(1, 0.2 * 25.4))\n\n    # Add a paragraph\n    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.\" \n    story.append(Paragraph(long_text, styles['Normal']))\n\n    # Build the PDF document\n    doc.build(story)\n    print(f\"PDF created: {filename}\")\n\nif __name__ == \"__main__\":\n    create_pdf()","lang":"python","description":"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."},"warnings":[{"fix":"Review and update code for Python 3 compatibility, particularly regarding string types. Refer to ReportLab's change logs for detailed transitions.","message":"ReportLab 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.","severity":"breaking","affected_versions":"<3.0"},{"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.","message":"Reusing 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.","severity":"breaking","affected_versions":"All versions"},{"fix":"Always remember that y-coordinates increase upwards. Adjust calculations accordingly, or use helper functions/classes that abstract this if needed.","message":"The 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Optional 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'4.4.10':56 'activ':59 'api':28 'complex':44 'control':31 'creat':43 'current':53 'data':71 'data-driven':70 'document':19,46,85 'download':80 'driven':72 'dynam':69 'element':34 'featur':83 'flowabl':48 'framework':40 'generat':14,74,86 'graphic':21,87 'high':16 'high-qual':15 'higher':38 'higher-level':37 'includ':75 'level':27,39 'librari':12 'like':49 'low':26 'low-level':25 'maintain':60 'open':9 'open-sourc':8 'paragraph':50 'pdf':18,33,82,84 'platypus':41,89 'precis':30 'provid':23 'python':11 'qualiti':17 'regular':62 'report':73,88 'reportlab':1,4,57 'sourc':10 'structur':45 'tabl':52 'toolkit':2,5 'updat':63 'use':67 'version':55 'wide':66 'wikipedia':77","created_at":"2026-03-29T06:08:52.831447+00:00","updated_at":"2026-04-16T20:53:23.026890+00:00","problems":[{"fix":"Install the ReportLab library using pip: `pip install reportlab`","cause":"The ReportLab library is not installed in the current Python environment or is not accessible within the project's interpreter.","error":"ModuleNotFoundError: No module named 'reportlab'"},{"fix":"Import the `canvas` class explicitly: `from reportlab.pdfgen import canvas`","cause":"The `canvas` class is imported incorrectly, typically by importing the `reportlab.pdfgen` module instead of importing `canvas` directly from it.","error":"AttributeError: 'module' object has no attribute 'canvas'"},{"fix":"Provide a string argument for the output PDF filename when initializing Canvas, e.g., `c = canvas.Canvas(\"my_document.pdf\")`","cause":"The `canvas.Canvas` constructor was called without providing the mandatory `filename` argument, which specifies the name of the output PDF file.","error":"TypeError: __init__() missing 1 required positional argument: 'filename'"},{"fix":"Ensure the font file is a valid TTF and verify that the file path provided to `pdfmetrics.registerFont` is correct and accessible.","cause":"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.","error":"reportlab.pdfbase._fontdata.ReportLabFontError: Can't register font, not a TTF file?"},{"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`","cause":"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.","error":"reportlab.lib.utils.ImageReader.get==>Failed to find image data in PNG file"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"5.0.1","cli_name":"reportlab","cli_version":"sh: 1: reportlab: not found","type":"library","homepage":"https://www.reportlab.com/","github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/reportlab/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":"verified"}}