from
pptx
import
Presentation
from
pptx.util
import
Inches
import
os
def
convert_ppt_aspect_ratio(input_folder, output_folder):
if
not
os.path.exists(output_folder):
os.makedirs(output_folder)
for
file_name
in
os.listdir(input_folder):
if
file_name.endswith(
".pptx"
):
input_path
=
os.path.join(input_folder, file_name)
output_path
=
os.path.join(output_folder, file_name)
prs
=
Presentation(input_path)
prs.slide_width
=
Inches(
13.33
)
prs.slide_height
=
Inches(
7.5
)
for
slide
in
prs.slides:
for
shape
in
slide.shapes:
if
not
shape.is_placeholder:
shape.left
=
int
(shape.left
*
(
16
/
4
))
shape.top
=
int
(shape.top
*
(
9
/
3
))
shape.width
=
int
(shape.width
*
(
16
/
4
))
shape.height
=
int
(shape.height
*
(
9
/
3
))
prs.save(output_path)
print
(f
"已转换: {file_name}"
)
current_directory
=
os.getcwd()
input_folder
=
current_directory
output_folder
=
os.path.join(current_directory,
"output"
)
convert_ppt_aspect_ratio(input_folder, output_folder)