C#將PPT文件轉(zhuǎn)換成PDF文件
這里在提供C#代碼,將PPT轉(zhuǎn)成PDF.直接上代碼;
要引入Microsoft.Office.Interop.PowerPoint; 版本12.0.0.0;
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Runtime.InteropServices; using Microsoft.Office.Interop.PowerPoint; //Office 命名空間 namespace OfficeToPdf { //excel 類 class PowerPointConverter { //構(gòu)造函數(shù) public PowerPointConverter() { } /// <summary> /// 轉(zhuǎn)換PowerPoint 成PDF文檔 /// </summary> /// <param name="_lstrInputFile">原文件路徑</param> /// <param name="_lstrOutFile">pdf文件輸出路徑</param> /// <returns>true 成功</returns> public bool ConverterToPdf(string _lstrInputFile, string _lstrOutFile) { Microsoft.Office.Interop.PowerPoint.Application lobjPowerPointApp = null; Microsoft.Office.Interop.PowerPoint.Presentation lobjppt = null; object lobjMissing = System.Reflection.Missing.Value; object lobjSaveChanges = null; try { lobjPowerPointApp = new Microsoft.Office.Interop.PowerPoint.Application(); lobjppt = lobjPowerPointApp.Presentations.Open(_lstrInputFile, MSCore.MsoTriState.msoTrue, MSCore.MsoTriState.msoFalse, MSCore.MsoTriState.msoFalse); lobjppt.SaveAs(_lstrOutFile, PpSaveAsFileType.ppSaveAsPDF, MSCore.MsoTriState.msoCTrue); } catch (Exception ex) { //其他日志操作; return false; } finally { if (lobjppt != null) { lobjppt.Close(); Marshal.ReleaseComObject(lobjppt); lobjppt = null; } if (lobjPowerPointApp != null) { lobjPowerPointApp.Quit(); Marshal.ReleaseComObject(lobjPowerPointApp); lobjPowerPointApp = null; } //主動激活垃圾回收器,主要是避免超大批量轉(zhuǎn)文檔時,內(nèi)存占用過多,而垃圾回收器并不是時刻都在運行! GC.Collect(); GC.WaitForPendingFinalizers(); } return true; } } }
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
相關(guān)文章
關(guān)于C#數(shù)強轉(zhuǎn)會不會拋出異常詳解
這篇文章主要給大家介紹了關(guān)于C#數(shù)強轉(zhuǎn)會不會拋出異常的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-04-04C#結(jié)合JavaScript實現(xiàn)多文件上傳功能
在許多應(yīng)用場景里,多文件上傳是一項比較實用的功能,本文主要為大家詳細介紹了C#如何結(jié)合JavaScript實現(xiàn)多文件上傳功能,感興趣的小伙伴可以了解下2023-12-12c# WinForm制作圖片編輯工具(圖像拖動、縮放、旋轉(zhuǎn)、摳圖)
這篇文章主要介紹了c# WinForm制作圖片編輯工具(可實現(xiàn)圖像拖動、縮放、旋轉(zhuǎn)、摳圖),幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下2021-03-03WPF利用TextBlock實現(xiàn)查找結(jié)果高亮顯示效果
在應(yīng)用開發(fā)過程中,經(jīng)常遇到這樣的需求:通過關(guān)鍵字查找數(shù)據(jù),把帶有關(guān)鍵字的數(shù)據(jù)顯示出來,同時在結(jié)果中高亮顯示關(guān)鍵字,所以本文就來和大家介紹一下如何利用TextBlock實現(xiàn)查找結(jié)果高亮顯示效果吧2023-08-08