Python實現對PPT文件進行截圖操作的方法

字號:


    本文實例講述了Python實現對PPT文件進行截圖操作的方法。分享給大家供大家參考。具體分析如下:
    下面的代碼可以為powerpoint文件ppt進行截圖,可以指定要截取的幻燈片頁面,需要本機安裝了powerpoint,可以指定截圖的大小分辨率
    import os
    import comtypes.client
    def export_presentation(path_to_ppt, path_to_folder):
    if not (os.path.isfile(path_to_ppt) and os.path.isdir(path_to_folder)):
    raise "Please give valid paths!"
    powerpoint = comtypes.client.CreateObject("Powerpoint.Application")
    # Needed for script to work, though I don't see any reason why...
    powerpoint.Visible = True
    powerpoint.Open(path_to_ppt)
    # Or some other image types
    powerpoint.ActivePresentation.Export(path_to_folder, "JPG")
    #這里可以寫成:
    #Presentation.Slides[1].Export("C:/path/to/jpg.jpg","JPG",800,600);
    powerpoint.Presentations[1].Close()
    powerpoint.Quit()
    希望本文所述對大家的Python程序設計有所幫助。