I'm printing an HTML document successfully with the following code:
using (WebBrowser webBrowser = new WebBrowser())
{
webBrowser.DocumentText = text;
while (webBrowser.ReadyState != WebBrowserReadyState.Complete)
Application.DoEvents();
InternetExplorer internetExplorer = (InternetExplorer)webBrowser.ActiveXInstance;
internetExplorer.PrintTemplateTeardown += InternetExplorer_PrintTemplateTeardown;
internetExplorer.ExecWB(OLECMDID.OLECMDID_PRINT, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER);
while (!documentPrinted)
Application.DoEvents();
internetExplorer.PrintTemplateTeardown -= InternetExplorer_PrintTemplateTeardown;
}
Two problems:
- The printed paper has an header (
page 1 of 1
) and a footer (about:blank
anddate
). How can I print without them? - The printed paper is much longer than the actual HTML page content. How can I stop the printing when the content ends?