Reputation: 429
I have a WPF application with a list of documents. I have created a print all button, that sends all documents to my default printer. I want to give the user the ability to select a printer, and then send all documents to that printer.
But how do I show the print dialog and save the printer info? And how can I print to a specific printer after closing the dialog?
I have this in my print function, and that works fine (but for the wrong printer)
var p = new Process
{
StartInfo = new ProcessStartInfo
{
CreateNoWindow = true,
Verb = "print",
FileName = filePath
}
};
p.Start();
Upvotes: 1
Views: 2258
Reputation: 429
Thanks to Ray for lots of help.
The following method works fine for selecting a printer. The printer queue is captured when the user clicks "Print" on the print dialog box.
public PrintQueue SelectPrinter()
{
var dialog = new PrintDialog();
if (dialog.ShowDialog() == true)
{
if (dialog.PrintQueue != null)
return dialog.PrintQueue;
}
return null;
}
The print queue can then be used when printing multiple documents;
...
var startInfo = new ProcessStartInfo
{
CreateNoWindow = true,
Verb = "printTo",
FileName = filePath,
Arguments = printQueue.FullName, // <-- here
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = true,
};
var p = Process.Start(startInfo);
...
Upvotes: 2
Reputation: 8785
This is only a clue and not a complete answer but I think it could help.
You can list printers and change the default printer using the windows registry.
You can read and write in the registry using .NET framework in a easy way.
Upvotes: 0
Reputation: 46585
You could to use the PrintDialog
A common usage pattern would be
PrintDialog dialog = new PrintDialog();
if (dialog.ShowDialog() == true)
{
dialog.PrintVisual(visual, "Job Name");
//dialog.PrintDocument(paginator, "Document Name");
}
If you want to print from a file you'll need to load the file and create a DocumentPaginator. How to do that depends on the file format you're trying to print.
Upvotes: 1