-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_pdf.py
More file actions
107 lines (93 loc) · 2.78 KB
/
create_pdf.py
File metadata and controls
107 lines (93 loc) · 2.78 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import pdfkit
from jinja2 import Template
import streamlit as st
from db import get_user_info, get_latest_chat_report
config = pdfkit.configuration(wkhtmltopdf=r'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe')
html_template = """
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<style>
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR&display=swap');
body {
font-family: 'Noto Sans KR', sans-serif;
background-color: #ffffff;
color: #2e2e2e;
margin: 30px;
line-height: 1.8;
}
h1 {
font-size: 28px;
font-weight: 700;
border-bottom: 2px solid #ddd;
padding-bottom: 10px;
margin-bottom: 30px;
}
.info-box {
padding: 20px;
border: 1px solid #e0e0e0;
background-color: #f0f4f8;
border-radius: 10px;
margin-bottom: 40px;
}
.section {
margin-bottom: 40px;
padding: 20px;
border-radius: 12px;
border: 1px solid #e0e0e0;
background-color: #f9f9f9;
}
.section h3 {
font-size: 20px;
margin-bottom: 15px;
color: #444;
}
.section p {
font-size: 16px;
white-space: pre-line;
}
</style>
</head>
<body>
<h1>{{ report_date }} {{ name }}님 인지 훈련 리포트</h1>
<div class="info-box">
<h3>■ 환자 정보</h3>
<p><strong>이름:</strong> {{ name }}<br><strong>나이:</strong> {{ age }}세</p>
</div>
<div class="section">
<h3>■ 오늘의 대화 요약</h3>
<p>{{ chat_summary }}</p>
</div>
<div class="section">
<h3>■ 인지 훈련 종합 소견</h3>
<p>{{ memo }}</p>
</div>
</body>
</html>
"""
def generate_pdf_from_report(user_id):
user_info = get_user_info(user_id)
report = get_latest_chat_report(user_id)
if not user_info:
print("❌ 사용자 정보가 없습니다.")
return
if not report:
print("❌ 대화 리포트가 없습니다.")
return
name = user_info["name"]
age = user_info["age"]
summary = report["chat_summary"]
memo = report["memo"]
report_date = str(report["report_date"].date())
template = Template(html_template)
rendered_html = template.render(
name=name,
age=age,
report_date=report_date,
chat_summary=summary.replace("\n", "<br>"),
memo=memo.replace("\n", "<br>")
)
output_path=f"{report_date} {name}님 인지 훈련 리포트.pdf"
pdfkit.from_string(rendered_html, output_path, configuration=config)
print(f"✅ PDF 저장 완료: {output_path}")