【发布时间】:2017-05-01 20:03:44
【问题描述】:
我有以下 C# 代码可以成功打印提供的文件。这是在 Windows 7 中。
// Uses the Default settings of the Windows Environment to open the file and send to printer
// Seen: http://stackoverflow.com/a/6106155
public void printPdfHiddenProcess(string filename)
{
ProcessStartInfo info = new ProcessStartInfo();
Process p;
// Set process setting to be hidden
info.Verb = "print";
info.FileName = filename;
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
// Start hidden process
p = new Process();
p.StartInfo = info;
p.Start();
// Give the process some time
p.WaitForInputIdle();
Thread.Sleep(1000);
// Close it
if (p.CloseMainWindow() == false)
{
p.Close();
}
}
但是,这会导致它打印到默认打印机。 ProcessStartInfo 似乎没有提供可用于传递打印机名称的特定方法,但我可能遗漏了一些东西。
如何使用隐藏进程打印到特定打印机?
【问题讨论】:
标签: c# windows printing process