File size: 1,220 Bytes
6140c9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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