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”用戶),並賦予最大權限   

 

以上操作都設置了,應該就可以正常使用了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM