zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    虚拟机中Linux 下安装tools
    各个复位标志解析,让我们对MCU的程序的健康更有把控
    用过的两种鼠标右键添加快捷指令方法
    一个ftp协议传输文件之后执行脚本无法工作的情况
    一文入门Linux下gdb调试(二)
    一文入门Linux下gdb调试(一)
    VS CODE远程办公篇一
    Kwp2000协议的应用(程序后续篇)
    Kwp2000协议的应用(程序原理篇)
    Kwp2000协议的应用(硬件原理使用篇)
  • 原文地址:https://www.cnblogs.com/taizhouxiaoba/p/5011955.html
Copyright © 2011-2022 走看看