Printing Background Colors from WPF WebBrowser

ぐ巨炮叔叔 提交于 2019-12-13 04:26:17

问题


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!


回答1:


Assuming you're using 'SHDocVw.WebBrowser', you can use the ExecWB command. To print without the dialog, use the OLECMDEXECOPT_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)

browser.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
               SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, 
               "print_template.html", ref nullObject);

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.



来源:https://stackoverflow.com/questions/6062949/printing-background-colors-from-wpf-webbrowser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!