C# ppt-PDF

PPT를 PDF로 전환하는 C# 코드를 제공합니다.직접 부호 올리기;
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
    {
        //    
        public PowerPointConverter()
        { }

        /// <summary>
        ///   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;
                }

                //         ,             ,      ,               !
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return true;
        }
    }
}

좋은 웹페이지 즐겨찾기