简体   繁体   中英

How print dialog box selected printer to printing process

I am trying to print PDF file using Process

PrintDialog pdf = new PrintDialog();
if (pdf.ShowDialog() == DialogResult.OK)
{
  pdf.AllowSelection = true;
  pdf.AllowSomePages = true;
  ProcessStartInfo info = new ProcessStartInfo();
  info.Arguments = pdf.PrinterSettings.PrinterName;
  info.CreateNoWindow = true;
  info.Verb = "print";
  info.FileName = filename;
  //info.WindowStyle = ProcessWindowStyle.Hidden;
  try
  {
    Process p = new Process();
    p.StartInfo = info;
    p.EnableRaisingEvents = true; //Important line of code
    //p.PriorityBoostEnabled = true;
    p.Start();
    p.WaitForExit();
    p.Close();
  }
  catch (Exception ex){}
}
else
{
  MessageBox.Show("Print Canceled");
}
}
catch (Exception ex){}

But this code not take user selected printer for print process. It print pdf by default printer. what would be the fault? Thanks.

@RiksonTool,

Your code is printing to pdf by default printer as it is reading the settings from control panel of windows. This is not a fault, it is a manifestation of the default settings in windows.

Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM