Python 编程实现 PPT 批量转图片(PNG/JPG) 在日常工作中我们经常需要把 PPT 转成图片用于博客、报告或者分享。Python 提供了一个非常方便的方式通过win32com自动化PowerPoint实现批量导出幻灯片。一、安装依赖pip install pywin32注意该方法仅在 Windows 系统上有效并且需要安装 MicrosoftPowerPoint二、完整代码importosfrompathlibimportPathimportpythoncomfromwin32com.clientimportDispatchdefppt_to_images(ppt_path,output_dirNone,image_formatPNG,width1920,height1080): 将 PPT 每一页导出为图片 参数: ppt_path: PPT 文件路径 output_dir: 输出文件夹默认在 PPT 同目录下创建同名文件夹 image_format: 图片格式可选 PNG / JPG width: 导出宽度 height: 导出高度 ppt_pathPath(ppt_path)ifnotppt_path.exists():raiseFileNotFoundError(f找不到文件:{ppt_path})ifoutput_dirisNone:output_dirppt_path.parent/f{ppt_path.stem}_imageselse:output_dirPath(output_dir)output_dir.mkdir(parentsTrue,exist_okTrue)pythoncom.CoInitialize()powerpointNonepresentationNonetry:powerpointDispatch(PowerPoint.Application)powerpoint.Visible1presentationpowerpoint.Presentations.Open(str(ppt_path),WithWindowFalse)# 导出全部幻灯片presentation.Export(str(output_dir),image_format,width,height)print(f转换完成图片已保存到:{output_dir})exceptExceptionase:print(f转换失败:{e})finally:ifpresentation:presentation.Close()ifpowerpoint:powerpoint.Quit()pythoncom.CoUninitialize()if__name____main__:ppt_filerD:\目标文件.pptppt_to_images(ppt_file)三、使用方法修改ppt_file为你的 PPT 路径。运行脚本会在同目录下生成PPT文件名_images文件夹里面是每一页的图片。3. 可通过参数调整图片格式和分辨率ppt_to_images(ppt_file, image_formatJPG, width2560, height1440)Windows 用户可以用 withWindowTrue 看到转换过程调试更方便。如果导出的图片有白边可以考虑在 PPT 里调整幻灯片尺寸

相关新闻

最新新闻

10分钟掌握Flow.js:构建企业级文件分块上传与断点续传系统

10分钟掌握Flow.js:构建企业级文件分块上传与断点续传系统

10分钟掌握Flow.js:构建企业级文件分块上传与断点续传系统 【免费下载链接】flow.js A JavaScript library providing multiple simultaneous, stable, fault-tolerant and resumable/restartable file uploads via the HTML5 File API. 项目地址: https://gitcod…

2026/7/18 10:10:09
Local RAG与Ollama集成:5步配置本地LLM环境

Local RAG与Ollama集成:5步配置本地LLM环境

Local RAG与Ollama集成:5步配置本地LLM环境 【免费下载链接】local-rag Ingest files for retrieval augmented generation (RAG) with open-source Large Language Models (LLMs), all without 3rd parties or sensitive data leaving your network. 项目地址: h…

2026/7/18 10:10:09
(三)MySQL之库表设计篇:一、二、三、四、五范式、BC范式与反范式详解!

(三)MySQL之库表设计篇:一、二、三、四、五范式、BC范式与反范式详解!

引言MySQL的库表设计,在很多时候我们都是率性而为,往往在前期的设计中考虑并不全面,同时对于库表结构的划分也并不明确,所以很多时候在开发过程中,代码敲着敲着会去重构某张表结构,甚至大面积重构多张表结构…

2026/7/18 10:10:09
Linux命令用法

Linux命令用法

文章目录前言一、Linux基础命令1. Linux目录结构2. Linux命令入门3. 目录切换相关命令(cd、pwd)4. 相对路径、绝对路径和特殊路径符5. 创建目录命令((mkdir)6. 文件操作命令part1(touch、cat、more)7. 文件操作命令par…

2026/7/18 10:10:09
如何快速构建专属AI音色模型:RVC语音转换框架的完整指南

如何快速构建专属AI音色模型:RVC语音转换框架的完整指南

如何快速构建专属AI音色模型&#xff1a;RVC语音转换框架的完整指南 【免费下载链接】Retrieval-based-Voice-Conversion-WebUI Easily train a good VC model with voice data < 10 mins! 项目地址: https://gitcode.com/GitHub_Trending/re/Retrieval-based-Voice-Conve…

2026/7/18 10:10:09
专业iOS设备固件恢复指南:掌握idevicerestore的5个核心技巧

专业iOS设备固件恢复指南:掌握idevicerestore的5个核心技巧

专业iOS设备固件恢复指南&#xff1a;掌握idevicerestore的5个核心技巧 【免费下载链接】idevicerestore Restore/upgrade firmware of iOS devices 项目地址: https://gitcode.com/gh_mirrors/id/idevicerestore idevicerestore是一款强大的命令行工具&#xff0c;专为…

2026/7/18 10:05:09

月新闻