[C#]使用預設印表機列印pdf文件

  • 3673
  • 0

使用預設印表機列印pdf文件。

private void PrintFile(string pdfPath)
{
   System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();

   pd.DefaultPageSettings.PrinterSettings.Copies = 2;
   pd.DefaultPageSettings.PrinterSettings.PrinterName = @"Print1";
            
   Process ps = new Process();
   ProcessStartInfo startInfo = new ProcessStartInfo();
   startInfo.UseShellExecute = true;
   startInfo.Verb = "Print";
   startInfo.CreateNoWindow = true;
   startInfo.WindowStyle = ProcessWindowStyle.Hidden;
   startInfo.Arguments = @"/p /h \" + pdfPath + "\" \"" + pd.PrinterSettings.PrinterName + " \"";

   startInfo.FileName = pdfPath;
   ps.StartInfo = startInfo;

   ps.Start();
   ps.WaitForExit();
   ps.Dispose();
            
}