C# 实现PPT 每一页转成图片

要实现PPT转图片,首先须要引用两个DLL。app

我这里用的这个这个版本ide

Microsoft.Office.Interop.PowerPoint 12.0ui

Microsoft Office 12.0 object Libraryspa

以下图:code

 

代码以下:orm

 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();
        }
相关文章
相关标签/搜索