Last modified: Oct 10, 2026

Add Images and Tables in ReportLab

ReportLab is a powerful Python library for generating PDFs programmatically. It allows developers to create professional documents with text, images, and tables. To get started, ensure you install ReportLab using the installation instructions provided in the official documentation.

Adding Images

To insert an image into a PDF, use the Image() class. This class accepts parameters like file path, width, and height. Always import necessary classes from reportlab.platypus.


from reportlab.platypus import SimpleDocTemplate, Image

# Create a PDF document
doc = SimpleDocTemplate("output.pdf")
story = []

# Add an image to the story
im = Image("my_image.png", width=100, height=100)
story.append(im)

# Build the PDF
doc.build(story)

# Output: A PDF named 'output.pdf' with your image embedded.

Tip: Ensure the image path is correct. Supported formats include PNG, JPEG, and GIF.

Adding Tables

Tables are created using the Table() class. Define data as a list of lists. Apply styles with TableStyle() for borders, backgrounds, and alignment.


from reportlab.platypus import Table, TableStyle
from reportlab.lib import colors

# Define table data
data = [
    ['Name', 'Age', 'City'],
    ['Alice', '30', 'New York'],
    ['Bob', '25', 'Los Angeles']
]

# Create table and apply style
table = Table(data)
table.setStyle(TableStyle([
    ('BACKGROUND', (0, 0), (-1, 0), colors.grey),
    ('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
    ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
    ('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)
doc.build(story)

# Output: A table with styled headers and alternating row colors.

Combining Images and Tables

You can add both elements to the same document. Append each element to the story list in order.


# Add image first
story.append(Image("logo.png", width=50, height=50))

# Add table next
story.append(table)

doc.build(story)

Advanced Features

ReportLab supports advanced layouts, charts, and styling. Explore the official documentation for features like flowables, page templates, and custom fonts.

Conclusion

Adding images and tables in ReportLab enhances PDF quality. Use Image() for visuals and Table() with TableStyle() for structured data. Practice with examples to master PDF generation. For deeper insights, refer to the official documentation.