要实现PPT转图片,首先需要引用两个DLL。
我这里用的这个这个版本
Microsoft.Office.Interop.PowerPoint 12.0
Microsoft Office 12.0 object Library
如下图:


代码如下:
private void pptToImg(string pptPath, string imgPath)
{
var app = new Microsoft.Office.Interop.PowerPoint.Application();
var ppt = app.Presentations.Open(pptPath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
var index = 0;
var fileName = Path.GetFileNameWithoutExtension(pptPath);
foreach (Microsoft.Office.Interop.PowerPoint.Slide slid in ppt.Slides)
{
++index;
//设置图片大小
slid.Export(imgPath+string.Format("page{0}.png",index.ToString()), "png", 1024, 768);
//根据屏幕尺寸。设置图片大小
//slid.Export(imgPath+string.Format("page{0}.jpg",index.ToString()), "jpg", Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
}
//释放资源
ppt.Close();
app.Quit();
GC.Collect();
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

评论(0)