這是一個(gè)Python腳本,能夠批量地將微軟Powerpoint文件(.ppt或者.pptx)轉(zhuǎn)換為pdf格式。
使用說(shuō)明
1、將這個(gè)腳本跟PPT文件放置在同一個(gè)文件夾下。
2、運(yùn)行這個(gè)腳本。
全部代碼
import comtypes.clientimport osdef init_powerpoint(): powerpoint = comtypes.client.CreateObject("Powerpoint.Application") powerpoint.Visible = 1 return powerpointdef ppt_to_pdf(powerpoint, inputFileName, outputFileName, formatType = 32): if outputFileName[-3:] != 'pdf': outputFileName = outputFileName + ".pdf" deck = powerpoint.Presentations.Open(inputFileName) deck.SaveAs(outputFileName, formatType) # formatType = 32 for ppt to pdf deck.Close()def convert_files_in_folder(powerpoint, folder): files = os.listdir(folder) pptfiles = [f for f in files if f.endswith((".ppt", ".pptx"))] for pptfile in pptfiles: fullpath = os.path.join(cwd, pptfile) ppt_to_pdf(powerpoint, fullpath, fullpath)if __name__ == "__main__": powerpoint = init_powerpoint() cwd = os.getcwd() convert_files_in_folder(powerpoint, cwd) powerpoint.Quit()源碼地址
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林站長(zhǎng)站。
新聞熱點(diǎn)
疑難解答
圖片精選