PDF report using image, charts and Paragraphs

Interactive Google Colab Practice Notebook

Practice assembling a multi-component ReportLab PDF report containing images, bar charts, line graphs, dynamic tables, shapes, and formatted text paragraphs directly inside Google Colab.

View on GitHub Open In Colab
Creating PDF report by using charts, table, graphs with text paragraphs by combination of components


We are adding five different components to our report. We created the images, charts, graphs, and paragraphs separately and imported them into our main.py script.

from chart_verticalbar_chart import d
from table_1_basic import t 
from chart_linechart import line_chart
from paragraph1 import p1, p2, p3
from chart_2_circle import d_circle

We set the path with file name in our main.py file and this file finally creates the PDF document.

from pathlib import Path

# Portable cross-platform file path construction
my_path = Path.home() / 'pdf_reports' / 'my_pdf.pdf'
PDF report with image, charts and tables

Adding Image 🔝

Change the path of the image here.
Adding image to PDF

c.drawImage('images/top2.jpg', 0.1*inch, 10*inch)  # image at left side top

Adding Vertical Bar chart 🔝

Bar charts in PDF

from chart_verticalbar_chart import d
d.wrapOn(c, 400, 400)
d.drawOn(c, 3*inch, 7.5*inch)   # vertical bar chart

Adding Table 🔝

Table from different data sources to PDF file

from table_1_basic import t 
t.wrapOn(c, width, height)     
t.drawOn(c, 3.6*inch, 5.6*inch) # table at right side

Adding Paragraphs 🔝

Paragraph

from paragraph1 import p1, p2, p3
p1.wrapOn(c, 200, 200)
p1.drawOn(c, 0.6*inch, 9.4*inch) # top paragraph of text 
p2.wrapOn(c, 200, 200)         
p2.drawOn(c, 0.6*inch, 6.4*inch) # middle paragraph of text 
p3.wrapOn(c, 200, 200)
p3.drawOn(c, 0.6*inch, 4.4*inch) # last paragraph of text

Adding Shapes (Circles) 🔝

PDF Circles & Shapes

from chart_2_circle import d_circle
d_circle.wrapOn(c, 100, 100)
d_circle.drawOn(c, 4*inch, 2.4*inch) # circles drawn at right

Adding Line Chart 🔝

Line charts in PDF

from chart_linechart import line_chart
line_chart.wrapOn(c, 810, 200)
line_chart.drawOn(c, 0.6*inch, 0.1*inch) # line chart at bottom

Complete Script: main.py 🔝

from pathlib import Path
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.units import inch
from chart_verticalbar_chart import d
from table_1_basic import t 
from chart_linechart import line_chart
from paragraph1 import p1, p2, p3
from chart_2_circle import d_circle

output_dir = Path('output')
output_dir.mkdir(exist_ok=True)
my_path = output_dir / 'my_pdf_report.pdf'

c = canvas.Canvas(str(my_path), pagesize=letter)
width, height = letter

c.drawImage('images/top2.jpg', 0.1*inch, 10*inch)  # image at left side top 
d.wrapOn(c, 400, 400)
d.drawOn(c, 3*inch, 7.5*inch)   # vertical bar chart 
t.wrapOn(c, width, height)     
t.drawOn(c, 3.6*inch, 5.6*inch) # table at right side
p1.wrapOn(c, 200, 200)
p1.drawOn(c, 0.6*inch, 9.4*inch) # top paragraph of text 
p2.wrapOn(c, 200, 200)         
p2.drawOn(c, 0.6*inch, 6.4*inch) # middle paragraph of text 
p3.wrapOn(c, 200, 200)
p3.drawOn(c, 0.6*inch, 4.4*inch) # last paragraph of text 
d_circle.wrapOn(c, 100, 100)
d_circle.drawOn(c, 4*inch, 2.4*inch) # circles drawn at right 
line_chart.wrapOn(c, 810, 200)
line_chart.drawOn(c, 0.6*inch, 0.1*inch) # line chart at bottom
c.save()
print(f"Report generated successfully at: {my_path}")

Practical Uses of Multi-Component PDF Reports

Combining distinct graphical, tabular, and textual elements into a single PDF report provides significant business utility:

  • Executive Dashboards: Combine high-level KPIs, summary paragraphs, and bar graphs to present key financial metrics in a concise single-page layout.
  • Sales & Operational Audits: Display historical performance trends using line charts alongside dynamic itemized data tables for regional performance breakdowns.
  • Automated Periodical Reporting: Automatically generate weekly or monthly status documents by importing reusable modular chart components across different data streams.

Common Errors & Troubleshooting

  • ModuleNotFoundError: Raised when component files (e.g., chart_verticalbar_chart.py) are not located in the Python execution path. Ensure all sub-modules are placed in the root execution folder or properly configured as package imports.
  • Overlap of Visual Elements: Occurs when drawOn(c, x, y) coordinates conflict. Remember that ReportLab coordinate origins $(0,0)$ start at the **bottom-left** corner of the page.
  • FileNotFoundError on Images: Using absolute OS-specific paths (e.g., D:\top2.jpg) often fails across different environments. Always use relative paths or pathlib.Path to ensure cross-platform compatibility.

Frequently Asked Questions (FAQ)

Q: How do `wrapOn()` and `drawOn()` work together in ReportLab canvas drawing?
A: `wrapOn(canvas, width, height)` calculates the layout dimensions required for the object within a bounded area, while `drawOn(canvas, x, y)` renders the wrapped object directly onto the canvas at coordinate $(x, y)$.

Q: Can I build multi-page reports using this canvas method?
A: Q: Yes. Call c.showPage() to start a new blank page on the canvas before invoking additional drawOn() functions.

Further Reading & Related Tutorials


Download .zip file with all source codes/files

Python PDF Line charts in PDF Pie Charts
PDF Mark sheet by using data from SQLite database



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer