当前位置: 移动技术网 > IT编程>开发语言>.net > asp.net实现将ppt文档转换成pdf的方法

asp.net实现将ppt文档转换成pdf的方法

2017年12月12日  | 移动技术网IT编程  | 我要评论

救命病爱,水怜黛心玉娇溶,长春461骨科医院

本文实例讲述了asp.net实现将ppt文档转换成pdf的方法。分享给大家供大家参考。具体实现方法如下:

一、添加引用

复制代码 代码如下:
using microsoft.office.core;
using microsoft.office.interop.powerpoint;

二、转换方法

复制代码 代码如下:
///<summary>       
/// 把powerpoint文件转换成pdf格式文件      
///</summary>       
///<param name="sourcepath">源文件路径</param>    
///<param name="targetpath">目标文件路径</param>
///<returns>成功返回true,失败返回false</returns>
public static bool pptconverttopdf(string sourcepath, string targetpath)
{
        bool result;
        ppsaveasfiletype ppsaveasfiletype = ppsaveasfiletype.ppsaveaspdf;//转换成pdf
        object missing = type.missing;
        microsoft.office.interop.powerpoint.applicationclass application = null;
        presentation persentation = null;
        try
        {
            application = new microsoft.office.interop.powerpoint.applicationclass();
            persentation = application.presentations.open(sourcepath, msotristate.msotrue, msotristate.msofalse, msotristate.msofalse);
            if (persentation!=null)
            {
                persentation.saveas(targetpath, ppsaveasfiletype, msotristate.msotrue);
            }
            result = true;
        }
        catch
        {
            result = false;
        }
        finally
        {
            if (persentation != null)
            {
                persentation.close();
                persentation = null;
            }
            if (application != null)
            {
                application.quit();
                application = null;
            }
        }
        return result;
}

三、调用

复制代码 代码如下:
officetopdf.ppttopdf("d:\\12345.pptx", "d:\\12345.pdf");

希望本文所述对大家的asp.net程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网