0

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
  • 147
  • 1
  • 2
  • 13

1 Answers1

0

@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

Hamza Ahmed
  • 1,571
  • 4
  • 18
  • 35