溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

C#中怎么將PPT文件轉(zhuǎn)換成PDF文件

發(fā)布時(shí)間:2021-06-16 14:46:58 來源:億速云 閱讀:400 作者:Leah 欄目:編程語言

今天就跟大家聊聊有關(guān)C#中怎么將PPT文件轉(zhuǎn)換成PDF文件,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

要引入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;
        }
        //主動(dòng)激活垃圾回收器,主要是避免超大批量轉(zhuǎn)文檔時(shí),內(nèi)存占用過多,而垃圾回收器并不是時(shí)刻都在運(yùn)行!
        GC.Collect();
        GC.WaitForPendingFinalizers();
      }
      return true;
    }
  }
}

看完上述內(nèi)容,你們對(duì)C#中怎么將PPT文件轉(zhuǎn)換成PDF文件有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝大家的支持。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI