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 類(lèi)
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;
}
//主動(dòng)激活垃圾回收器,主要是避免超大批量轉(zhuǎn)文檔時(shí),內(nèi)存占用過(guò)多,而垃圾回收器并不是時(shí)刻都在運(yùn)行!
GC.Collect();
GC.WaitForPendingFinalizers();
}
return true;
}
}
}
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
相關(guān)文章
關(guān)于C#版Nebula客戶(hù)端編譯的問(wèn)題
這篇文章主要介紹了C#版Nebula客戶(hù)端編譯的問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-07-07
Unity 2017使用UGUI實(shí)現(xiàn)大轉(zhuǎn)盤(pán)抽獎(jiǎng)
這篇文章主要為大家詳細(xì)介紹了Unity 2017使用UGUI實(shí)現(xiàn)大轉(zhuǎn)盤(pán)抽獎(jiǎng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-02-02
關(guān)于C#連接FTP時(shí)路徑問(wèn)題的解決方法
最近在工作中遇到一個(gè)需求,需要利用C#連接FTP,在連接過(guò)程中遇到一個(gè)問(wèn)題,所以下面這篇文章主要給大家介紹了關(guān)于C#連接FTP時(shí)路徑問(wèn)題的解決方法,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-08-08
C#創(chuàng)建WebService接口并連接的全過(guò)程
工作時(shí)遇到需要請(qǐng)求客戶(hù)的接口返回?cái)?shù)據(jù),要求使用WebService,借此機(jī)會(huì)記錄一下,下面這篇文章主要給大家介紹了關(guān)于C#創(chuàng)建WebService接口并連接的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12
C#身份證識(shí)別相關(guān)技術(shù)功能詳解
這篇文章主要介紹了C#身份證識(shí)別相關(guān)技術(shù)詳解,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07
Unity中Instantiate實(shí)例化物體卡頓問(wèn)題的解決
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)離線(xiàn)計(jì)時(shí)器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-10-10
在C# WPF下自定義滾動(dòng)條ScrollViewer樣式的操作
這篇文章主要介紹了在C# WPF下自定義滾動(dòng)條ScrollViewer樣式的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-01-01
C#?wpf利用附加屬性實(shí)現(xiàn)任意控件拖動(dòng)
這篇文章主要為大家詳細(xì)介紹了C#?WPF如何利用附加屬性對(duì)幾種拖動(dòng)方式進(jìn)行封裝,實(shí)現(xiàn)復(fù)用性,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-11-11

