Printing background colors in WPF WebBrowser

I am currently printing the contents of a WPF web browser as follows:

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 content, the background colors do not print - everything is solid whiteness. Is there a way to tell WebBrowser to also print background colors?

In addition, it still brings up a print popup dialog. Does anyone know which command is for printing content without a dialog box?

Thank you so much!

0
c # browser printing wpf
source share
1 answer

Assuming you are using "SHDocVw.WebBrowser", you can use the ExecWB command. To print without dialogue, use the constant OLECMDEXECOPT_PROMPTUSER ( 1 ). You can also pass the IE print template (HTML file only) for more control over how the page is displayed.

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, this is one of the options you can specify in the LayoutRect print LayoutRect . All settings of the print dialog box are stored in the registry , but a print template is preferable because it does not change the system-wide settings.

+1
source share

All Articles