快捷搜索:

C#中将word文档转换为tif文件的方法

预备工作:完整安装office 2003,然后添加COM组件引用,Microsoft WORD 11.0
                          在打印机和传真机选项中将Microsoft Office Document Image Writer设为默认打印机
       需添加的命名空间:using Microsoft.Office.Interop.Word; 
                                           using System.IO;
  class PrintDocToTif
    ...{
        string tifPath = null; 
            //设置生成的tif文件路径
            //路径名的命名规则为无后缀名,否则调用 varDoc.PrintOut方法时会打开打印预览窗体
        public PrintDocToTif(string buildTifPath)
        ...{
            this.tifPath = buildTifPath;
        }

        /**//// <summary>
        /// 生成无后缀名的tif文件
        /// </summary>
        /// <param>源WORD文件</param>
        /// <param></param>
        public void PrintTo(object sourceFile)
        ...{
            try
            ...{
                //生成的tif路径
                object OutputFileName = (object)tifPath;

  object varMissing = Type.Missing;

                //定义Word实例对象
                Microsoft.Office.Interop.Word.Application varWord = new Microsoft.Office.Interop.Word.Application();

                //设置Word的虚拟打印机
                varWord.ActivePrinter = "Microsoft Office Document Image Writer"
 //定义Word文档实例对象
                Microsoft.Office.Interop.Word.Document varDoc = varWord.Documents.Open
                                                               (ref sourceFile, ref varMissing, ref varMissing, ref varMissing, ref varMissing,
                                                                ref varMissing, ref varMissing, ref varMissing, ref varMissing,

您可能还会对下面的文章感兴趣: