需求:
利用WebBrowser 读取html内容并打印小票
问题:
打印文件会带有IE footer, 如果需要打印的文件内容本身很短,则会出现很长的一段白纸 然后在最后打印出 比如 about:blank + 日期
原因是 WebBrowser 会调用IE 的设置,@"Software\Microsoft\Internet Explorer\PageSetup";
解决办法:
在打印时重新设置PageSetup
string keyName = @"Software\Microsoft\Internet Explorer\PageSetup";
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName, true))
{
if (key != null)
{
string old_footer = key.GetValue("footer").ToString();
string old_header = key.GetValue("header").ToString();
key.SetValue("footer", "");
key.SetValue("header", "");
webBrowser1.Print();
key.SetValue("footer", old_footer);
key.SetValue("header", old_header);
}
}