码迷,mamicode.com
首页 > Web开发 > 详细

asp.net将ppt文档转换成pdf

时间:2014-11-14 09:16:30      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:http   io   ar   os   sp   strong   文件   div   on   

一、添加引用

 

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

 

二、转换方法

 
C# 代码   复制
bubuko.com,布布扣
bubuko.com,布布扣    ///<summary>        
bubuko.com,布布扣    /// 把PowerPoint文件转换成PDF格式文件       
bubuko.com,布布扣    ///</summary>        
bubuko.com,布布扣    ///<param name="sourcePath">源文件路径</param>     
bubuko.com,布布扣    ///<param name="targetPath">目标文件路径</param> 
bubuko.com,布布扣    ///<returns>成功返回true,失败返回false</returns> 
bubuko.com,布布扣    public static bool PPTConvertToPDF(string sourcePath, string targetPath)
bubuko.com,布布扣    {
bubuko.com,布布扣        bool result;
bubuko.com,布布扣        PpSaveAsFileType ppSaveAsFileType = PpSaveAsFileType.ppSaveAsPDF;//转换成pdf
bubuko.com,布布扣        object missing = Type.Missing;
bubuko.com,布布扣        Microsoft.Office.Interop.PowerPoint.ApplicationClass application = null;
bubuko.com,布布扣        Presentation persentation = null;
bubuko.com,布布扣        try
bubuko.com,布布扣        {
bubuko.com,布布扣            application = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
bubuko.com,布布扣            persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
bubuko.com,布布扣            if (persentation!=null)
bubuko.com,布布扣            {
bubuko.com,布布扣                persentation.SaveAs(targetPath, ppSaveAsFileType, MsoTriState.msoTrue);
bubuko.com,布布扣            }
bubuko.com,布布扣            result = true;
bubuko.com,布布扣        }
bubuko.com,布布扣        catch
bubuko.com,布布扣        {
bubuko.com,布布扣            result = false;
bubuko.com,布布扣        }
bubuko.com,布布扣        finally
bubuko.com,布布扣        {
bubuko.com,布布扣            if (persentation != null)
bubuko.com,布布扣            {
bubuko.com,布布扣                persentation.Close();
bubuko.com,布布扣                persentation = null;
bubuko.com,布布扣            }
bubuko.com,布布扣            if (application != null)
bubuko.com,布布扣            {
bubuko.com,布布扣                application.Quit();
bubuko.com,布布扣                application = null;
bubuko.com,布布扣            }
bubuko.com,布布扣        }
bubuko.com,布布扣        return result;
bubuko.com,布布扣    }
bubuko.com,布布扣

 

三、调用

 

OfficeToPdf.PPTToPDF("d:\\12345。pptx", "d:\\12345。pdf"); 

asp.net将ppt文档转换成pdf

标签:http   io   ar   os   sp   strong   文件   div   on   

原文地址:http://www.cnblogs.com/ranran/p/4092826.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!