批量將ppt轉(zhuǎn)換為pdf的Python代碼 只要27行!
更新時(shí)間:2018年02月26日 15:24:36 作者:zhusongziye
這篇文章主要為大家詳細(xì)介紹了批量將ppt轉(zhuǎn)換為pdf的Python代碼,只要27行,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
這是一個(gè)Python腳本,能夠批量地將微軟Powerpoint文件(.ppt或者.pptx)轉(zhuǎn)換為pdf格式。
使用說明
1、將這個(gè)腳本跟PPT文件放置在同一個(gè)文件夾下。
2、運(yùn)行這個(gè)腳本。
全部代碼
import comtypes.client
import os
def init_powerpoint():
powerpoint = comtypes.client.CreateObject("Powerpoint.Application")
powerpoint.Visible = 1
return powerpoint
def 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í)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
PyQt5?QLineEdit校驗(yàn)器限制輸入實(shí)例代碼
QLineEdit類是一個(gè)單行文本控件,可輸入單行字符串,可以設(shè)置回顯模式(Echomode)和掩碼模式,下面這篇文章主要給大家介紹了關(guān)于PyQt5?QLineEdit校驗(yàn)器限制輸入的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-05-05
用Python實(shí)現(xiàn)隨機(jī)森林算法的示例
這篇文章主要介紹了用Python實(shí)現(xiàn)隨機(jī)森林算法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-08-08
Python實(shí)現(xiàn)Mysql數(shù)據(jù)庫連接池實(shí)例詳解
這篇文章主要介紹了Python實(shí)現(xiàn)Mysql數(shù)據(jù)庫連接池實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-04-04

