Reputation: 849
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:
page 1 of 1
) and a footer (about:blank
and date
). How can I print without them?Upvotes: 2
Views: 2942
Reputation: 849
I've found a solution without using a custom print template.
This code clears the header and footer:
const string keyName = @"Software\Microsoft\Internet Explorer\PageSetup";
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName, true))
{
if (key != null)
{
key.SetValue("footer", string.Empty);
key.SetValue("header", string.Empty);
}
}
In order to cut the paper in the thermal printer when the browser's content ends, I've added the PRINT_WAITFORCOMPLETION
parameter to this line:
internetExplorer.ExecWB(OLECMDID.OLECMDID_PRINT, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, Win32.PRINT_WAITFORCOMPLETION);
Upvotes: 4