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);