-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpptScript.py
More file actions
112 lines (112 loc) · 4.86 KB
/
pptScript.py
File metadata and controls
112 lines (112 loc) · 4.86 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
108
109
110
111
112
import sys
from pptx import Presentation
from pptx.util import Inches
from pptx.dml.color import RGBColor
from pptx.enum.text import PP_ALIGN
from pptx.util import Pt
import os
os.chdir("D:\\revere\\office\\uploads");
print("Output from Python PPt")
mylist = sys.argv[1].split(',')
destination = sys.argv[2]
mainPrs = Presentation(destination)
blank_slide_layout = mainPrs.slide_layouts[5]
left = top = Inches(0)
for a in mylist:
print(a)
prs = Presentation(a);
s=0
for slide in prs.slides:
a=0
b=0
text_runs = ""
if(len(slide.shapes)>0):
mainSlide = mainPrs.slides.add_slide(blank_slide_layout)
for shape in slide.shapes:
print(shape.shape_type)
if(shape.is_placeholder):
h= shape.placeholder_format.type
print(h)
try:
if(h == 18):
path = str(s)+'mypic.jpg'
with open(path, 'wb') as f:
f.write(shape.image.blob)
s=s+1
try:
mainSlide.shapes.add_picture(path, left, top, height = mainPrs.slide_height)
except:
print("Unable to add to slide")
os.remove(path)
except:
print("An exception occurred")
if shape.has_text_frame:
for paragraph in shape.text_frame.paragraphs:
for run in paragraph.runs:
text_runs = text_runs + run.text
if(shape.shape_type == 13):
a=a+1
path = str(s)+'mypic.jpg'
with open(path, 'wb') as f:
f.write(shape.image.blob)
s=s+1
try:
mainSlide.shapes.add_picture(path, left, top, height = mainPrs.slide_height)
except:
print("Unable to add to slide")
os.remove(path)
if(shape.shape_type == 1):
b=b+1
if(shape.shape_type == 6):
for shape in shape.shapes:
print(shape.shape_type)
if(shape.is_placeholder):
h= shape.placeholder_format.type
print(h)
try:
if(h == 18):
path = str(s)+'mypic.jpg'
with open(path, 'wb') as f:
f.write(shape.image.blob)
s=s+1
try:
mainSlide.shapes.add_picture(path, left, top, height = mainPrs.slide_height)
except:
print("Unable to add to slide")
os.remove(path)
except:
print("An exception occurred")
if shape.has_text_frame:
for paragraph in shape.text_frame.paragraphs:
for run in paragraph.runs:
text_runs = text_runs + run.text
if(shape.shape_type == 13):
a=a+1
path = str(s)+'mypic.jpg'
with open(path, 'wb') as f:
f.write(shape.image.blob)
s=s+1
try:
mainSlide.shapes.add_picture(path, left, top, height = mainPrs.slide_height)
except:
print("Unable to add to slide")
os.remove(path)
print("a= "+str(a)+",b= "+str(b))
halfI = Inches(0.5)
textBoxTop = mainPrs.slide_height - halfI
textBox = mainSlide.shapes.add_textbox(left, top = textBoxTop,width = mainPrs.slide_width, height = halfI)
fill = textBox.fill
fill.solid()
fill.fore_color.rgb = RGBColor(235, 192, 52)
textBox.text_frame.word_wrap = True
p = textBox.text_frame.paragraphs[0]
p.alignment = PP_ALIGN.CENTER
run = p.add_run()
run.text = text_runs
font = run.font
font.name = 'Calibri'
font.size = Pt(24)
font.bold = True
print("print outside loop before saving")
mainPrs.save(destination)
print("file saved to " + destination)