最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python實(shí)現(xiàn)批量將PPT轉(zhuǎn)換成長圖

 更新時(shí)間:2023年08月25日 09:04:58   作者:谷雨之際  
這篇文章主要為大家詳細(xì)介紹了如何利用Python實(shí)現(xiàn)批量將PPT轉(zhuǎn)換成長圖,并且圖片名稱與PPT文件名稱相同,保存位置相同,感興趣的小伙伴可以了解下

語言:python 3

用法:點(diǎn)擊運(yùn)行后,彈出窗口,選擇文件夾,程序運(yùn)行會(huì)將文件夾內(nèi)的所有PPT文件全部轉(zhuǎn)換成PPT長圖,圖片名稱與PPT文件名稱相同,保存位置相同。

如運(yùn)行中報(bào)錯(cuò),需要自行根據(jù)報(bào)錯(cuò)內(nèi)容按照缺失的庫

共分享兩種代碼,可以嘗試運(yùn)行。

代碼1

需安裝庫

#安裝庫
pip install pyautogui
#安裝庫
pip install  pillow
 
import os
import comtypes.client
from tkinter import Tk, filedialog
from PIL import Image
def ppt_to_images(ppt_file):
 try:
    # 導(dǎo)入comtypes.client模塊并創(chuàng)建PowerPoint應(yīng)用程序?qū)ο?
    powerpoint = comtypes.client.CreateObject("Powerpoint.Application")
    # 設(shè)置PowerPoint應(yīng)用程序?yàn)榭梢姞顟B(tài),便于觀察操作過程(可選),修改為0后報(bào)錯(cuò)
    #powerpoint.Visible = 1
    # 打開PPT文件,并返回Presentation對象
    presentation = powerpoint.Presentations.Open(ppt_file)
    for i, slide in enumerate(presentation.slides):      #slide是幻燈片序列
        slide.Export(f"slide_{i}.png", "PNG")
    # 關(guān)閉PPT文件
    presentation.Close()
    # 退出PowerPoint應(yīng)用程序
    powerpoint.Quit()
    presentation = None
    print(ppt_file+"分圖完成!")
 except Exception as e:
        print("分圖時(shí)發(fā)生錯(cuò)誤:", str(e))
def merge_images(directory, png_file):
    try:
        Image.MAX_IMAGE_PIXELS = 2 ** 40
        images = []  # 存儲圖片對象
        for file in os.listdir(directory):
            file_path = os.path.join(directory, file)
            if os.path.isfile(file_path) and file.lower().endswith(".png"):
                image = Image.open(file_path)
                images.append(image)
        if len(images) == 0:
            print("未找到PNG格式的圖片文件")
            return None
        max_width = max(image.size[0] for image in images)  # 獲取最大寬度
        total_height = sum(image.size[1] for image in images)  # 計(jì)算總高度
        final_image = Image.new("RGBA", (max_width, total_height), (0, 0, 0, 0))  # 創(chuàng)建最終圖像
        # 逐個(gè)粘貼圖片到最終圖像中
        y_offset = 0
        for image in images:
            final_image.paste(image, (0, y_offset))
            y_offset += image.size[1]
        final_image.save(png_file)
        print("已生成圖片"+png_file)
        if final_image:
            for file in os.listdir(directory):
                file_path = os.path.join(directory, file)
                if os.path.isfile(file_path) and file.lower().endswith(".png") and "slide" in file:
                    os.remove(file_path)
                    print("已刪除圖片"+file)
    except Exception as e:
        print("合并圖片時(shí)發(fā)生錯(cuò)誤:", str(e))
def select_directory():
    try:
        root = Tk()
        root.withdraw()
        directory = filedialog.askdirectory(title="選擇目錄")
        ppt_files = [f for f in os.listdir(directory) if f.endswith('.pptx')or f.endswith('.ppt')]
        for ppt_file in ppt_files:
          try:
            #print("directory" + directory)
            if ppt_file.lower().endswith(".pptx"):
               png_file = os.path.join(directory, ppt_file[:-5] + ".png")
               ppt_to_images(ppt_file)  # PPT to image
               merge_images(directory, png_file)  # image to images
            elif ppt_file.lower().endswith(".ppt"):
                png_file = os.path.join(directory, ppt_file[:-4] + ".png")
                ppt_to_images(ppt_file)  # PPT to image
                merge_images(directory, png_file)  # image to images
          except Exception as e:
           print("處理PPT文件時(shí)發(fā)生錯(cuò)誤,跳過該文件:", str(e))
        print("轉(zhuǎn)換完成!")
    except Exception as e:
        print("選擇目錄并轉(zhuǎn)換PPT文件時(shí)發(fā)生錯(cuò)誤:", str(e))
# 選擇目錄并轉(zhuǎn)換PPT到PDF格式,再將PDF轉(zhuǎn)換為長圖
select_directory()
 

代碼2

import os
import comtypes.client
from tkinter import Tk, filedialog
from pptx import Presentation
from PIL import Image
#PPT轉(zhuǎn)換成圖片
def ppt_to_images(ppt_file, png_file):
    #presentation = powerpoint.Presentations.Open(ppt_file)
    presentation = Presentation(os.path.join(png_file, ppt_file))
    for i, slide in enumerate(presentation.slides):      #slide是幻燈片序列
        slide.export(f"{png_file}/slide_{i}.png")     #將PPT轉(zhuǎn)換成圖片并保存到目錄下
    print("PPT轉(zhuǎn)換為圖像完成!")
#將圖片拼接成長圖
def merge_images(ppt_path, output_file):
    images = [Image.open(f"{ppt_path}/{img}") for img in os.listdir(ppt_path) if img.endswith(".png")]
    widths, heights = zip(*(img.size for img in images))
    total_height = sum(heights)
    max_width = max(widths)
    merged_image = Image.new("RGB", (max_width, total_height))
    y_offset = 0
    for img in images:
        merged_image.paste(img, (0, y_offset))
        y_offset += img.size[1]
    merged_image.save(output_file)
    print("圖像拼接完成!")
def ppt_to_pdf(ppt_path, pdf_file):   #ppt路徑和pdf的路徑
    # 導(dǎo)入comtypes.client模塊并創(chuàng)建PowerPoint應(yīng)用程序?qū)ο?
    powerpoint = comtypes.client.CreateObject("Powerpoint.Application")
    # 設(shè)置PowerPoint應(yīng)用程序?yàn)榭梢姞顟B(tài),便于觀察操作過程(可選),修改為0后報(bào)錯(cuò)
    powerpoint.Visible = 1
    # 打開PPT文件,并返回Presentation對象
    presentation = powerpoint.Presentations.Open(ppt_path)
    # 將打開的PPT文件導(dǎo)出為PDF文件(第二個(gè)參數(shù)2表示導(dǎo)出為PDF格式)
    presentation.ExportAsFixedFormat(pdf_file, 2)
    # 輸出轉(zhuǎn)換完成的信息
    print(ppt_path + "轉(zhuǎn)PDF完成!")
def select_directory():
    root = Tk()
    root.withdraw()
    directory = filedialog.askdirectory(title="選擇目錄")
    ppt_files = [f for f in os.listdir(directory) if f.endswith('.pptx')]
    for ppt_file in ppt_files:
        ppt_path = os.path.join(directory, ppt_file)       #ppt_path ppt的路徑,拼接ppt
        pdf_file = os.path.join(directory, ppt_file[:-4] + ".pdf")    #pdf文件
        png_file= os.path.join(directory, ppt_file[:-4] + ".png")
        ppt_to_pdf(ppt_path, pdf_file)
    print("轉(zhuǎn)換完成!")
# 選擇目錄并轉(zhuǎn)換PPT到PDF格式,再將PDF轉(zhuǎn)換為長圖
select_directory()

到此這篇關(guān)于Python實(shí)現(xiàn)批量將PPT轉(zhuǎn)換成長圖的文章就介紹到這了,更多相關(guān)Python PPT轉(zhuǎn)長圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 在python中實(shí)現(xiàn)將一張圖片剪切成四份的方法

    在python中實(shí)現(xiàn)將一張圖片剪切成四份的方法

    今天小編就為大家分享一篇在python中實(shí)現(xiàn)將一張圖片剪切成四份的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • Python實(shí)現(xiàn)多張圖片合成文字的效果

    Python實(shí)現(xiàn)多張圖片合成文字的效果

    前段時(shí)間看到有人問如何使用Python實(shí)現(xiàn)多張圖片組成文字的效果?覺得還挺有意思,于是嘗試做了一下,剛好趕上端午節(jié),所以打算從網(wǎng)上下載1000張王心凌的照片,組成端午安康的字樣,感興趣的可以了解一下
    2022-06-06
  • 利用python如何處理nc數(shù)據(jù)詳解

    利用python如何處理nc數(shù)據(jù)詳解

    目前很多數(shù)據(jù)以nc格式存儲,下面這篇文章主要給大家介紹了關(guān)于利用python如何處理nc數(shù)據(jù)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值。需要的朋友們下面來一起看看吧
    2018-05-05
  • Python實(shí)現(xiàn)經(jīng)典算法拓?fù)渑判?、字符串匹配算法和最小生成樹?shí)例

    Python實(shí)現(xiàn)經(jīng)典算法拓?fù)渑判?、字符串匹配算法和最小生成樹?shí)例

    這篇文章主要介紹了Python實(shí)現(xiàn)經(jīng)典算法拓?fù)渑判?、字符串匹配算法和最小生成樹?shí)例,拓?fù)渑判?、字符串匹配算法和最小生成樹是?jì)算機(jī)科學(xué)中常用的數(shù)據(jù)結(jié)構(gòu)和算法,它們在解決各種實(shí)際問題中具有重要的應(yīng)用價(jià)值,需要的朋友可以參考下
    2023-08-08
  • Python遠(yuǎn)程控制Windows服務(wù)器的方法總結(jié)

    Python遠(yuǎn)程控制Windows服務(wù)器的方法總結(jié)

    在信息時(shí)代的洪流中,掌握一門編程語言已經(jīng)成為一項(xiàng)必備技能,Python,這門以簡潔、易學(xué)、強(qiáng)大著稱的編程語言,更是成為無數(shù)開發(fā)者的大寶劍,今天,我們要探討的就是如何用 Python 遠(yuǎn)程控制 Windows 服務(wù)器,需要的朋友可以參考下
    2024-07-07
  • python查看某個(gè)包的當(dāng)前安裝版本及最新版本的五種方法

    python查看某個(gè)包的當(dāng)前安裝版本及最新版本的五種方法

    這篇文章主要介紹了5種查看Python包最新版本的方法,包括使用pip的--outdated參數(shù)、pipsearch命令(已被棄用)、pipindexversions命令、pypi-simple工具和在Python腳本中使用pip,需要的朋友可以參考下
    2025-01-01
  • Python dict和defaultdict使用實(shí)例解析

    Python dict和defaultdict使用實(shí)例解析

    這篇文章主要介紹了Python dict和defaultdict使用實(shí)例解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-03-03
  • 使用Python實(shí)現(xiàn)多功能課堂點(diǎn)名器與抽簽工具

    使用Python實(shí)現(xiàn)多功能課堂點(diǎn)名器與抽簽工具

    這篇文章主要為大家詳細(xì)介紹了如何使用Python實(shí)現(xiàn)多功能課堂點(diǎn)名器,也可以用作抽簽工具,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-02-02
  • Python安裝lz4-0.10.1遇到的坑

    Python安裝lz4-0.10.1遇到的坑

    本篇文章給大家分享了Python安裝lz4-0.10.1的詳細(xì)過程以及遇到的坑,需要的讀者們參考下。
    2018-05-05
  • python opencv設(shè)置攝像頭分辨率以及各個(gè)參數(shù)的方法

    python opencv設(shè)置攝像頭分辨率以及各個(gè)參數(shù)的方法

    下面小編就為大家分享一篇python opencv設(shè)置攝像頭分辨率以及各個(gè)參數(shù)的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-04-04

最新評論

洛阳市| 久治县| 新兴县| 大港区| 衡南县| 竹北市| 南投市| 荥经县| 远安县| 水城县| 伊川县| 股票| 合肥市| 南开区| 陕西省| 沅陵县| 盱眙县| 麦盖提县| 马龙县| 仙居县| 尉犁县| 威海市| 宁阳县| 乃东县| 界首市| 镇原县| 儋州市| 行唐县| 淅川县| 巴彦淖尔市| 宣城市| 渝中区| 镇宁| 含山县| 双流县| 临洮县| 浮山县| 闽清县| 麻城市| 科技| 咸宁市|