PDF document is always sent to the default printer despite selecting another printer in the print dialog box

869 views Asked by At

I need to have the users of a wpf application to be able to choose printers when they print a particular .pdf file. I can get it to print but it always goes to the default printer no matter what I do. Most documents for this application need to go to the default black and white printer. This particular document needs to to to a color printer. When I run this code the print dialog box displays but despite selecting a printer that is not the default printer, the print job always goes to the default printer.

    private void PrintRedLightGreenLightFile()
    {
        PrintDialog pd = new PrintDialog();

            pd.ShowDialog();
            ProcessStartInfo info = new ProcessStartInfo();
            info.FileName = this.redlightgreenlightfilepath;
            info.Verb = "PrintTo";
            info.CreateNoWindow = true;
            info.WindowStyle = ProcessWindowStyle.Hidden;
            Process.Start(info);        }
1

There are 1 answers

1
Clemens On

Instead of starting a separate printing process you should use the PrintDocument method of the PrintDialog as explained in the MSDN (see the Examples sections).

Apart from this, the information about the targeted printer can be found in the PrintDialog's PrintQueue property and should somehow be communicated to your print process.