我有以下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似乎没有提供我可以用来传递打印机名称的特定方法,但我可能会遗漏一些东西。
如何使用隐藏流程打印到特定打印机?
答案 0 :(得分:1)
Print
转到默认设置,使用另一个PrintTo
并命名。与保存 vs 另存为
info.Verb = "PrintTo"; // was "Print"
string PrinterName = "Some Printer"; // add printer specific name here...
info.Arguments = PrinterName;