C# PPT转图片的解决方案

1、PPT转图片代码


using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;


public
bool ConvertPics(string sourcePath, string targetPath, PpSaveAsFileType targetFileType) { bool result; object missing = Type.Missing; Microsoft.Office.Interop.PowerPoint.Application application = null; // Microsoft.Office.Interop.Word.Application Presentation persentation = null; Presentation persentationCopy = null; try { Thread.Sleep(2000); application = new Microsoft.Office.Interop.PowerPoint.Application(); persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); // persentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue); //整个ppt的文件转换为其他的格式 // persentation.Slides[1].Export(targetPath + "\\ppt.jpg", "JPG", 800, 600); //将ppt中的某张转换为图片文件 persentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue); //整个ppt的文件转换为其他的格式 result = true; } catch (Exception ex) { ex.ToString(); result = false; new SSP.School.BLL.Temp().AddMessage("sourcePath=" + sourcePath + ";targetPath=" + targetPath + ";" + ex.ToString(), " PPT转码服务异常(ConvertPics)"); } finally { if (persentation != null) { persentation.Close(); persentation = null; } if (application != null) { application.Quit(); application = null; } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } return result; }

 

需要注意的服务器设置:

1、在web.config添加配置节:

  

 <identity impersonate="true" userName="administrator" password="123456" />

 

2、若不行,进行如下设置

  (1)打开开始菜单的运行对话框,输入dcomcnfg命令,确定,这时会弹出组件服务窗口   
  (2)展开计算机-〉我的电脑-〉DCOM配置,找到Microsoft   Powerpoint应用程序节点   
  (3)单击右键-〉属性,选中“安全”选项,在下面三个项目都选择“自定义”,并单击编辑按钮   
  (4)在启动权限对话框中点击添加按钮,添加相应的用户(注意:如果是WIN2000,XP,则添加“机器名/ASPNET”用户,
我这里是以WIN2003为例,WIN2003是添加“NETWORK   Service”用户),并赋予最大权限   

 

以上操作都设置了,应该就可以正常使用了

posted on 2016-08-19 12:13  普向东的博客  阅读(3389)  评论(1编辑  收藏  举报

导航