【发布时间】:2014-04-29 19:38:21
【问题描述】:
我正在使用以下代码成功打印 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)。没有它们我该如何打印? - 打印的纸张比实际的 HTML 页面内容长得多。内容结束时如何停止打印?
【问题讨论】:
-
谢谢,该主题提供了丰富的信息,但我无法更改正在打印的网页。有没有办法在不改变页面的情况下清除这些页眉和页脚?
-
是的,该线程中有一个指向
IDM_PRINT的链接,允许设置自定义页眉/页脚(包括一个空的)。
标签: c# html printing webbrowser-control printing-web-page