预备工作:完整安装
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 name="sourceFile">源WORD文件</param>
/// <param name="destiFile"></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,