ProfessorLeVesseur's picture
Create Report.py
6140c9f verified
raw
history blame
1.22 kB
import io
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Image, Paragraph, Spacer
from reportlab.lib.styles import getSampleStyleSheet
def create_combined_pdf(intervention_fig, student_metrics_fig, recommendations):
buffer = io.BytesIO()
doc = SimpleDocTemplate(buffer, pagesize=letter)
styles = getSampleStyleSheet()
# Create a list to hold the PDF elements
elements = []
# Add the intervention statistics chart
img_buffer = io.BytesIO()
intervention_fig.write_image(img_buffer, format="png")
img_buffer.seek(0)
elements.append(Image(img_buffer, width=500, height=300))
elements.append(Spacer(1, 12))
# Add the student metrics chart
img_buffer = io.BytesIO()
student_metrics_fig.write_image(img_buffer, format="png")
img_buffer.seek(0)
elements.append(Image(img_buffer, width=500, height=300))
elements.append(Spacer(1, 12))
# Add the AI recommendations
elements.append(Paragraph("AI Recommendations", styles['Heading1']))
elements.append(Paragraph(recommendations, styles['BodyText']))
# Build the PDF
doc.build(elements)
buffer.seek(0)
return buffer