我正在使用以下代码成功打印HTML文档:
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;
}
两个问题:
page 1 of 1
)和页脚(about:blank
和date
)。没有它们我怎么打印?答案 0 :(得分:4)
我找到了一个不使用自定义打印模板的解决方案 此代码清除页眉和页脚:
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);
}
}
为了在浏览器内容结束时在热敏打印机中剪切纸张,我已将PRINT_WAITFORCOMPLETION
参数添加到此行:
internetExplorer.ExecWB(OLECMDID.OLECMDID_PRINT, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, Win32.PRINT_WAITFORCOMPLETION);