从 WPF Web 浏览器打印背景颜色
目前,我正在打印 WPF WebBrowser 的内容,如下所示:
mshtml.IHTMLDocument2 doc = WebBrowser.Document as mshtml.IHTMLDocument2;
doc.execCommand("Print", true, null);
我的 HTML 内容包含带有背景颜色的表格。目前,当我打印内容时,背景颜色不会打印——一切都是纯白色的。有没有办法告诉网络浏览器也打印背景颜色?
此外,这仍然会导致弹出打印对话框。有谁知道无对话框打印内容的命令是什么?
多谢!
Currently, I'm printing the contents of a WPF WebBrowser like so:
mshtml.IHTMLDocument2 doc = WebBrowser.Document as mshtml.IHTMLDocument2;
doc.execCommand("Print", true, null);
My HTML content has tables with background colors. Currently, when I print the content, the background colors do not print -- everything is solid white. Is there a way to tell the WebBrowser to print the background colors as well?
Also, this still causes a print dialog to pop up. Does anyone know what the command is to print the contents dialog-less?
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您使用“SHDocVw.WebBrowser”,则可以使用
ExecWB
命令。要在不显示对话框的情况下进行打印,请使用OLECMDEXECOPT_PROMPTUSER
(1
) 常量。您还可以传递 IE 打印模板(只是一个 HTML 文件),以更好地控制页面的显示方式。它是这样的(取自 this MSDN 问题)
至于背景,它似乎是您可以在打印模板的
LayoutRect
。所有打印对话框设置都存储在注册表中,但最好使用打印模板,因为它不会更改系统范围的设置。Assuming you're using 'SHDocVw.WebBrowser', you can use the
ExecWB
command. To print without the dialog, use theOLECMDEXECOPT_PROMPTUSER
(1
) constant. You can also pass an IE print template (just an HTML file) for more control over how the page is displayed.It's something like this (taken from this MSDN question)
As for the background, it appears to be one of the options you can specify in the print template's
LayoutRect
. All print dialog settings are stored in the registry, but a print template is preferable because it won't change system-wide settings.