-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_pdf.py
54 lines (39 loc) · 1.05 KB
/
generate_pdf.py
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
from md2pdf.core import md2pdf
from datetime import date
import uuid
titles = [
"Problem Description:",
"Solutions Being Used So Far:",
"Expected Business Value:",
"How AI can be Applied:",
"Potential Costs and Risks:",
"Data sources required by this use case:"
]
def isTitle(s):
if s.strip() in titles:
return True
return False
md_header1 = '''
<img src="https://i.ibb.co/G3sx1Q3/rsz-1full-loco.png">
<h1> Report for '''
md_header2 = ''' </h1>
---
'''
md_footer1 = '''
---
<img src="https://i.ibb.co/G3sx1Q3/rsz-1full-loco.png">
This report was generated by CanAI
<br>
'''
def generate_pdf(companyName, report):
blocks = report.split('\n')
md_data = md_header1 + companyName + md_header2
for s in blocks:
if isTitle(s):
md_data += f"<h3> {s} </h3>\n"
else:
md_data += f"{s}\n"
md_data += md_footer1 + str(date.today()) + "\n"
pdfName = str(uuid.uuid4())+".pdf"
md2pdf("./pdfs/"+pdfName, md_content=md_data, css_file_path="style.css")
return pdfName