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 里调整幻灯片尺寸

相关新闻

最新新闻

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现 【免费下载链接】serenity The Serenity Operating System 🐞 项目地址: https://gitcode.com/GitHub_Trending/se/serenity 导读 本文以 getopt(3) 手册 为核心&a…

2026/10/1 19:32:24
轻量服务器还是ECS?大促云服务器选购与避坑实战指南

轻量服务器还是ECS?大促云服务器选购与避坑实战指南

每年大促节点,群里永远有人在问同一个问题:“38元的轻量服务器到底怎么抢?为什么我每次点进去都是已售罄?68元直购和99元的ECS我到底选哪个?”作为一个常年帮团队和自己采购云服务器的老用户,我太清楚这种纠…

2026/9/30 21:32:07
为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南 【免费下载链接】agents Multi-harness agentic plugin marketplace for Claude Code, Codex, Cursor, OpenCode, GitHub Copilot, and Google Antigravity 项目地址:…

2026/10/2 15:29:32
PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署 【免费下载链接】PaddleOCR Turn any PDF or image document into structured data for your AI. A powerful, lightweight OCR toolkit that bridges the gap between i…

2026/10/3 7:41:27
Spring源码解析:构造器注入的类型转换与候选匹配机制

Spring源码解析:构造器注入的类型转换与候选匹配机制

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/1 19:32:35
openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由 【免费下载链接】openai-agents-python A lightweight, powerful framework for multi-agent workflows 项目地址: https://gitcode.com/GitHub_Trending/op/openai-agents-pyth…

2026/9/30 21:32:11

日新闻

周新闻

月新闻