听申论课的时候发现站长的课件都是单个ppt文件,想合并成一个pdf文件放在pad上看,于是就用gpt写了一个脚本,输入文件夹地址,检测里面的ppt文件并转化成pdf文件。
import os
import win32com.client
def ppt_to_pdf(input_folder):
powerpoint = win32com.client.Dispatch("Powerpoint.Application")
ppt_files = [file for file in os.listdir(input_folder) if file.lower().endswith((".ppt", ".pptx"))]
for ppt_file in ppt_files:
ppt_path = os.path.join(input_folder, ppt_file)
pdf_file = os.path.splitext(ppt_file)[0] + ".pdf"
pdf_path = os.path.join(input_folder, pdf_file)
if not os.path.exists(pdf_path):
presentation = powerpoint.Presentations.Open(ppt_path)
presentation.SaveAs(pdf_path, 32) # 32 is the value for PDF format
presentation.Close()
powerpoint.Quit()
if __name__ == "__main__":
folder_address = "C:\\你的文件夹路径" # 在这里替换成你想要的文件夹地址
ppt_to_pdf(folder_address)