# report.py from fpdf import FPDF import os class ReportBuilder: def __init__(self, output_path="report.pdf"): self.pdf = FPDF() self.pdf.set_auto_page_break(auto=True, margin=15) self.output_path = output_path def add_title(self, title): self.pdf.add_page() self.pdf.set_font("Arial", "B", 16) self.pdf.cell(0, 10, title, ln=True, align="C") self.pdf.ln(10) def add_section(self, title, body): self.pdf.set_font("Arial", "B", 14) self.pdf.cell(0, 10, title, ln=True) self.pdf.set_font("Arial", "", 12) self.pdf.multi_cell(0, 10, body) self.pdf.ln(5) def add_plot(self, image_path, caption): if os.path.exists(image_path): self.pdf.image(image_path, w=160) self.pdf.set_font("Arial", "I", 11) self.pdf.multi_cell(0, 8, f" {caption}") self.pdf.ln(5) def save(self): self.pdf.output(self.output_path)