-
Notifications
You must be signed in to change notification settings - Fork 1
/
PptToMd.py
44 lines (37 loc) · 1.3 KB
/
PptToMd.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
from pptx import Presentation
import markdown2
INPUT_FILE = './input/Review1.pptx'
OUTPUT_DIR = './output/'
OUTPUT_FILE = OUTPUT_DIR+'Review1'
prs = Presentation(INPUT_FILE)
text = []
counter = 0
isFirstSlide = True
for slide in prs.slides:
isFirst = True
for shape in slide.shapes:
if not shape.has_text_frame:
filename = str(counter)+'.'+shape.image.ext
#print(filename)
with open(OUTPUT_DIR+filename,'wb') as f:
f.write(shape.image.blob)
text.append('!['+filename+']('+filename+')\n\n')
counter += 1
continue
if isFirst:
if isFirstSlide:
text.append('# ')
isFirstSlide = False
else:
text.append('## ')
isFirst = False
for paragraph in shape.text_frame.paragraphs:
text.append(('* '*paragraph.level)+paragraph.text)
text.append('\n\n')
text.append('\n')
dumpString = ''.join(text)
dumpString = dumpString.encode('utf8') # https://stackoverflow.com/questions/6048085/writing-unicode-text-to-a-text-file
with open(OUTPUT_FILE+'.md','w') as f:
f.write(dumpString)
with open(OUTPUT_FILE+'.html','w') as f:
f.write(markdown2.markdown(dumpString)+'<style>body{margin:5%}</style>')