Reputation: 4821
I have the following C# code that successfully prints a file that it is provided. This is in 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();
}
}
However, this causes it to print to the default printer. ProcessStartInfo doesn't appear to provide specific methods I can use to pass the printer name, but I might be missing something.
How can I print to a specific printer using a hidden process?
Upvotes: 0
Views: 3066
Reputation: 1075
Print
goes to the default, to use another you would use PrintTo
and name it. Similar to Save vs Save As
info.Verb = "PrintTo"; // was "Print"
string PrinterName = "Some Printer"; // add printer specific name here...
info.Arguments = PrinterName;
More info: Print documents... using the printto verb
Upvotes: 1