asp.net将ppt文档转换成pdf

一、添加引用

 

using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;

 

二、转换方法

 
C# 代码   复制
asp.net将ppt文档转换成pdf
///<summary>        
asp.net将ppt文档转换成pdf/// 把PowerPoint文件转换成PDF格式文件       
asp.net将ppt文档转换成pdf///</summary>        
asp.net将ppt文档转换成pdf///<param name="sourcePath">源文件路径</param>     
asp.net将ppt文档转换成pdf///<param name="targetPath">目标文件路径</param> 
asp.net将ppt文档转换成pdf///<returns>成功返回true,失败返回false</returns> 
asp.net将ppt文档转换成pdf    public static bool PPTConvertToPDF(string sourcePath, string targetPath)
{
asp.net将ppt文档转换成pdfbool result;
asp.net将ppt文档转换成pdf        PpSaveAsFileType ppSaveAsFileType = PpSaveAsFileType.ppSaveAsPDF;//转换成pdf
asp.net将ppt文档转换成pdf        object missing = Type.Missing;
asp.net将ppt文档转换成pdf        Microsoft.Office.Interop.PowerPoint.ApplicationClass application = null;
asp.net将ppt文档转换成pdf        Presentation persentation = null;
asp.net将ppt文档转换成pdftry
{
asp.net将ppt文档转换成pdf            application = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
asp.net将ppt文档转换成pdf            persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
asp.net将ppt文档转换成pdfif (persentation!=null)
{
asp.net将ppt文档转换成pdf                persentation.SaveAs(targetPath, ppSaveAsFileType, MsoTriState.msoTrue);
asp.net将ppt文档转换成pdf            }
asp.net将ppt文档转换成pdf            result = true;
asp.net将ppt文档转换成pdf        }
asp.net将ppt文档转换成pdfcatch
{
asp.net将ppt文档转换成pdf            result = false;
asp.net将ppt文档转换成pdf        }
asp.net将ppt文档转换成pdffinally
{
asp.net将ppt文档转换成pdfif (persentation != null)
{
asp.net将ppt文档转换成pdf                persentation.Close();
asp.net将ppt文档转换成pdf                persentation = null;
asp.net将ppt文档转换成pdf            }
asp.net将ppt文档转换成pdfif (application != null)
{
asp.net将ppt文档转换成pdf                application.Quit();
asp.net将ppt文档转换成pdf                application = null;
asp.net将ppt文档转换成pdf            }
asp.net将ppt文档转换成pdf        }
asp.net将ppt文档转换成pdfreturn result;
asp.net将ppt文档转换成pdf    }
asp.net将ppt文档转换成pdf

 

三、调用