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”用户),并赋予最大权限   

 

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

转载于:https://www.cnblogs.com/oriental/articles/5787163.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值