-
Notifications
You must be signed in to change notification settings - Fork 12
/
text2ppt.py
71 lines (63 loc) · 2.76 KB
/
text2ppt.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from pptx import Presentation
from pptx.util import Inches,Pt
from pptx.enum.text import MSO_ANCHOR, MSO_AUTO_SIZE
import addphoto
import re
#Create a new PowerPoint presentation
def presentate(defined_list):
prs = Presentation()
def add_slide(prs, layout, title, subtitle):
slide = prs.slides.add_slide(layout)
slide.shapes.title.text = title.strip()
slide.placeholders[1].text=subtitle
font = slide.shapes.title.text_frame.paragraphs[0].font
font.name = 'Arial'
font.size = Pt(30)
font.bold = True
font.italic = False
for x in slide.placeholders[1].text_frame.paragraphs:
font1= x.font
font1.name = 'Arial'
font1.size = Pt(16)
font1.bold = False
font1.italic = False
return slide
def add_slide1(prs, layout, title, subtitle):
slide = prs.slides.add_slide(layout)
slide.shapes.title.text = title.strip()
slide.placeholders[1].text=subtitle
font = slide.shapes.title.text_frame.paragraphs[0].font
font.name = 'Arial'
font.size = Pt(30)
font.bold = True
font.italic = False
for x in slide.placeholders[1].text_frame.paragraphs:
font1= x.font
font1.name = 'Arial'
font1.size = Pt(16)
font1.bold = False
font1.italic = False
return slide
def add_slide_img(prs, layout, img_path):
slide = prs.slides.add_slide(layout)
img_path = ""+img_path
left = Inches(1.10)
top = Inches(0.7)
width = Inches(8)
height = Inches(6)
pic = slide.shapes.add_picture(img_path, left, top, width, height)
title_slide_layout = prs.slide_layouts[1]
title_slide_layimg=prs.slide_layouts[6]
for d in defined_list:
d["Summary"] = [re.sub(r'\d+\.\s+', '', item).strip() for item in d["Summary"] if re.sub(r'\d+\.\s+', '', item).strip()]
for i in range (0,len(defined_list)):
slide = add_slide(prs, title_slide_layout, defined_list[i]["Topic"],"\n".join(defined_list[i]["Summary"][0:len(defined_list[i]["Summary"])//2]))
slide = add_slide(prs, title_slide_layout, defined_list[i]["Topic"],"\n".join(defined_list[i]["Summary"][len(defined_list[i]["Summary"])//2:]))
slide = add_slide1(prs, title_slide_layout, "Code Snippet For "+defined_list[i]["Topic"],defined_list[i]["Code"])
try:
slide2 = add_slide_img(prs,title_slide_layimg,"images/"+addphoto.get_images(defined_list[i]["Topic"],1)[0])
except:
slide2 = add_slide_img(prs,title_slide_layimg,"images/"+addphoto.get_images(defined_list[i]["Topic"],2)[1])
addphoto.empty_images()
# Save the presentation
prs.save("PPT.pptx")