void SendDocToPrinterSilently(string htmlfilename) { try { documentLoaded = false; documentPrinted = false; SHDocVw.InternetExplorer ie = new InternetExplorer(); ie.Visible = false; ie.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(ie_DocumentComplete); ie.PrintTemplateTeardown += new DWebBrowserEvents2_PrintTemplateTeardownEventHandler(ie_PrintTemplateTeardown); object missing = Missing.Value; ie.Navigate(htmlfilename, ref missing, ref missing, ref missing, ref missing); while (!documentLoaded && ie.QueryStatusWB(OLECMDID.OLECMDID_PRINT) != OLECMDF.OLECMDF_ENABLED) Thread.Sleep(100); ie.ExecWB(OLECMDID.OLECMDID_PRINT, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, ref missing, ref missing); while (!documentPrinted) Thread.Sleep(100); ie.DocumentComplete -= ie_DocumentComplete; ie.PrintTemplateTeardown -= ie_PrintTemplateTeardown; ie.Quit(); //SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer(); //IE.Visible = false; //IE.Silent = true; //IE.DocumentComplete += new SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(IE_DocumentComplete); //IE.PrintTemplateTeardown += new SHDocVw.DWebBrowserEvents2_PrintTemplateTeardownEventHandler(IE_PrintTemplateTeardown); //IE.Navigate(htmlfilename); } catch (Exception ex) { throw ex; } }
private void ie_DocumentComplete(object pDisp, ref object URL) { documentLoaded = true; }
private void ie_PrintTemplateTeardown(object pDisp) { documentPrinted = true; }