12
12
13
13
14
14
def ppt2video (pptx , video , timing , duration ,
15
- resolution , frames , quality , input_list , dict ):
15
+ resolution , frames , quality , dict ):
16
16
17
17
# Check if system requirements are met.
18
18
if sys .platform == "win32" :
@@ -31,78 +31,35 @@ def ppt2video(pptx, video, timing, duration,
31
31
# Open presentation
32
32
presentation = ppt .Presentations .Open (ppt_path , WithWindow = False )
33
33
34
- # slides_len = len(presentation.Slides)
35
-
36
- # powerpoint = win32com.client.Dispatch('PowerPoint.Application')
37
34
new_presentation = ppt .Presentations .Add (WithWindow = False )
38
- # slides = new_presentation.Slides
39
- # presentation.Slides[1].Copy()
40
- # new_presentation.Slides.Paste(1)
41
- # graphSlideID = gslides.Add(2, ppLayoutChart).SlideID
42
- # slides.FindBySlideID(graphSlideID)
43
35
36
+ # Compare input and slides by indexes, creating lists and comparing them
44
37
keys = [int (key ) for key , value in dict .items ()]
45
38
slides = [slide .SlideIndex for slide in presentation .Slides ]
46
39
# List of indexes with user input texts.
47
40
list = [key for key in keys if key in slides ]
48
41
49
42
# Slides indexes start with 1
50
43
for slide in presentation .Slides :
44
+ # Checking if user provided input
51
45
if slide .SlideIndex in list :
52
- # print(slide.SlideIndex)
53
- # print(dict.get(str(slide.SlideIndex)))
46
+ # Create new slide with new text
54
47
len_new_ppt = len (new_presentation .Slides )
55
48
new_slide = new_presentation .Slides .Add (
56
49
len_new_ppt + 1 , ppLayoutText )
57
50
new_slide .Shapes .addShape (
58
51
msoShapeRectangle , 150 , 150 , 250 , 250 ). \
59
52
TextFrame .TextRange .Text = dict .get (str (slide .SlideIndex ))
53
+ # Copying slide from original presentation and adding it new one.
60
54
slide .Copy ()
61
55
len_new_ppt = len (new_presentation .Slides )
62
56
new_presentation .Slides .Paste (len_new_ppt + 1 )
63
57
else :
64
- # print("no input", slide.SlideIndex)
58
+ # Adding slide to new presentation without user provided text
65
59
slide .Copy ()
66
60
len_new_ppt = len (new_presentation .Slides )
67
61
new_presentation .Slides .Paste (len_new_ppt + 1 )
68
62
69
-
70
- # for key, value in dict.items():
71
- # if slide.SlideIndex == int(key) and value != "":
72
- # len_new_ppt = len(new_presentation.Slides)
73
- # new_slide = new_presentation.Slides.Add(
74
- # len_new_ppt+1, ppLayoutText)
75
- # new_slide.Shapes.addShape(
76
- # msoShapeRectangle, 150, 150, 250, 250). \
77
- # TextFrame.TextRange.Text = value
78
- # slide.Copy()
79
- # len_new_ppt = len(new_presentation.Slides)
80
- # new_presentation.Slides.Paste(len_new_ppt+1)
81
- # else:
82
- # print(slide.SlideIndex)
83
-
84
- # print(slide.SlideIndex)
85
- print ("new presentation" , len (new_presentation .Slides ))
86
-
87
- # while input_list:
88
- # if len(input_list) == slides_len:
89
- # n = 1 # To track the slide number to be created
90
- # x = 0 # Index in the user input list
91
- # while x < slides_len:
92
- # # Create slide and insert it at n position with
93
- # # input_list[x] text
94
- # slide = presentation.Slides.Add(n, ppLayoutText)
95
- # slide.Shapes.addShape(
96
- # msoShapeRectangle, 150, 150, 250, 250). \
97
- # TextFrame.TextRange.Text = input_list[x]
98
- # n += 2
99
- # x += 1
100
- # break
101
- # else:
102
- # print("The length of input data should be equal to the \
103
- # slides count")
104
- # break
105
-
106
63
# Presentation.CreateVideo method (PowerPoint)
107
64
# https://docs.microsoft.com/en-us/office/vba/api/powerpoint.presentation.createvideo
108
65
new_presentation .CreateVideo (video_path , timing , duration ,
@@ -129,17 +86,20 @@ def ppt2video(pptx, video, timing, duration,
129
86
VertResolution = 720 # Int
130
87
FramesPerSecond = 24 # Int
131
88
Quality = 60 # Int
132
- # A list of user input text to insert before slides, starts with
133
- # the first slide. You can leave it blank and no additional
134
- # slides will be inserted in the video.
135
- user_input_list = []
136
- # key in the dict represents the index of the slides in the presentation
137
- # to be converted into video. Slides indexes start with 1, "first slide".
89
+
90
+ # User Input is in dictionary format. The keys in the dict represent the
91
+ # number of the slides in the presentation.
92
+ # Slides indexes, and input_dict as well, start with 1, "first slide", e.g.
93
+ # {"1":"input before slide number 1, the first slide",
94
+ # "2":"input before slide number 2, the second slide",
95
+ # "4":"input before slide number 4, the forth slide"}
96
+ # You can choose to what slides to add precending text and what slides
97
+ # to leave without additional input.
138
98
input_dict = { "1" :"input index 1" ,
139
99
"2" :"input index 2" , "4" :"input index 4" , "5" :"input index 5" ,
140
- "10" :"input index 10" , }
100
+ "10" :"input index 10" }
141
101
142
102
ppt2video (f"./{ file_name } " , f"./{ video_name } .mp4" ,
143
103
UseTimingsAndNarrations ,
144
104
DefaultSlideDuration , VertResolution ,
145
- FramesPerSecond , Quality , user_input_list , input_dict )
105
+ FramesPerSecond , Quality , input_dict )
0 commit comments