///
/// 打印word
///
/// word文件路径
/// 指定的打印机
public void Printword(string filepath,string printername)
{
//filepath=@"d:\b.doc";
//printername = "Microsoft XPS Document Writer";
try
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
//不现实调用程序窗口,但是对于某些应用无效 p.StartInfo.CreateNoWindow = true; p.StartInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Hidden; //采用操作系统自动识别的模式
http://doc.wendoc.comeShellExecute = true;
//要打印的文件路径
p.StartInfo.FileName = filepath;
Help help = new Help();
help.LogMessage(filepath + "---------" + printername);
//指定执行的动作,是打印,即print,打开是 open p.StartInfo.Verb = "print";
//获取当前默认打印机
string defaultPrinter = GetDefaultPrinter(); //将指定的打印机设为默认打印机
SetDefaultPrinter(printername);
第1/7页
//开始打印
p.Start();
//等待十秒
p.WaitForExit(10000);
//将默认打印机还原
SetDefaultPrinter(defaultPrinter);
}
catch (Exception ex)
{
help.LogMessage(filepath + "----" + printername + "-------" + ex.Message);
}
}
[DllImport("Winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool SetDefaultPrinter(string printerName);
[DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool GetDefaultPrinter(StringBuilder pszBuffer, ref int pcchBuffer); ///
/// 获取默认的打印机
///