• ASP.NET Word转为PDF


    1、首先安装 Microsoft Office 2007加载项:Microsoft Save as PDF-简体中文版:下载地址:

    http://download.microsoft.com/download/3/8/8/388812b2-0d3f-474e-a7ef-b095d3d0d3cd/SaveAsPDF.exe

    2,代码如下

    /// <summary>
    /// 转换word为pdf
    /// </summary>
    /// <param name="filename">doc文件路径</param>
    /// <param name="savefilename">pdf保存路径</param>
    void ConvertWordPDF1(object filename, object savefilename)
    {
    Object Nothing = System.Reflection.Missing.Value;
    //创建一个名为WordApp的组件对象
    wordApp = new ApplicationClass();
    //创建一个名为WordDoc的文档对象并打开
    Document doc = wordApp.Documents.Open(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
    //设置保存的格式
    object filefarmat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
    //保存为PDF
    doc.SaveAs(ref savefilename, ref filefarmat, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
    //关闭文档对象
    doc.Close(ref Nothing, ref Nothing, ref Nothing);
    //推出组建
    wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
    doc = null;
    wordApp = null;
    }

    //下面是各种转换格式

    object filefarmat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;//设置保存的格式,还可以为以下格式:

    Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML  //保存为HTML

    Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatRTF     //保存为RTF

    Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatText    //保存为文本

    Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXML    //保存为XML

    Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXPS    //保存为XPS

  • 相关阅读:
    企业项目开发--分布式缓存memcached(3)
    何时及为什么整理代码:现在,以后,从不
    【译文】程序员的两种类型
    国际化SEO优化的最佳实践
    动态代理的基本理解与基本使用
    Filter过滤器-JavaWeb三大组件之一
    java通过jdbc插入中文到mysql显示异常(问号或者乱码)
    BeanUtils封装对象时一直提示ClassNotFoundException:org.apache.commons.beanutils.BeanUtils
    MVC开发模式与javaEE三层架构
    JSP、EL表达式、JSTL
  • 原文地址:https://www.cnblogs.com/taizhouxiaoba/p/5011955.html
Copyright © 2020-2023  润新知