title: How to print WebBrowser control content without showing print dialog?
body: <p>I want to Print my HTML document directly to a specific network printer <strong>without printer dialog window</strong> when the end user click on PRINT button. I do search and  follow this but this opens a dialog window to save the document as pdf.</p>
  
  <p>Based On The Comments:</p>
  
  <pre><code> public static class PrinterClass
      {
          [DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
          public static extern bool SetDefaultPrinter(string Printer);
      }
  
  
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
              //List&lt;string&gt; st = new List&lt;string&gt;();
  
              //foreach (string strPrinter in PrinterSettings.InstalledPrinters)
              //{
              //    if (strPrinter.Contains("My Printer"))
              //    {
              //        PrinterClass.SetDefaultPrinter(strPrinter);
              //    }
              //    st.Add(strPrinter);
              //}
  
              SetDefaultPrinter("Send To OneNote 2016");
          }
  
          WebBrowser webBrowser = new WebBrowser();
          void Print(string str)
          {
              webBrowser.DocumentText = str;
  
              webBrowser.DocumentCompleted += webBrowser_DocumentCompleted;
          }
          void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
          {
              IHTMLDocument2 d2;
              d2 = (IHTMLDocument2)((WebBrowser)sender).Document.DomDocument;
  
              d2.execCommand("Print", false, null);
          }
  
          private void btn_print_Click(object sender, EventArgs e)
          {
              Print("&lt;html&gt;&lt;body&gt;..some html code..&lt;/body&gt;&lt;/html&gt;");
          }
  
          public static bool SetDefaultPrinter(string defaultPrinter)
          {
              using (ManagementObjectSearcher objectSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer"))
              {
                  using (ManagementObjectCollection objectCollection = objectSearcher.Get())
                  {
                      foreach (ManagementObject mo in objectCollection)
                      {
                          if (string.Compare(mo["Name"].ToString(), defaultPrinter, true) == 0)
                          {
                               mo.InvokeMethod("SetDefaultPrinter", null, null);
                              return true;
                          }
                      }
                  }
              }
              return false;
          }
      }
  </code></pre>