8

I'm writing application with WPF WebBrowser control. It's source is result of xml/xslt sourse from database.

In the window that contains WebBrowser there is button for printing with handler:

mshtml.IHTMLDocument2 doc = WBrowser.Document as mshtml.IHTMLDocument2;
doc.execCommand("Print", true, 0);

but in this case there is no background in printed document. I've researched this issue, and it's trouble with property in Internet Explorer page setup dialog - Allow the printing of background colors and images.

I've tried to change this by this code:

RegistryKey regKey = Registry.CurrentUser
        .OpenSubKey("Software", true)
        .OpenSubKey("Microsoft", true)
        .OpenSubKey("Internet Explorer", true)
        .OpenSubKey("PageSetup", true);

var defaultValue = regKey.GetValue("Print_Background");
regKey.SetValue("Print_Background", "yes");

but this is bad code. I don't want to change registry values for one simple bool parameter.

So, my question is: how can I change this parameter programmatically via code-behind without registry modification?

Thank you!

Max Zhukov
  • 877
  • 1
  • 8
  • 32

2 Answers2

5

The only way to modify the print settings without modifying the registry is via Print Templates and it seems like no one has really used them from the .NET web browser control.

However, this answer has additional resources regarding print templates and their usage from C++/win32.

If you're open to using ActiveX for printing the page, you could use the SHDocVw.WebBrowser which then gives you access to the ability to specify the print template, as noted in this answer

Community
  • 1
  • 1
zastrowm
  • 8,017
  • 3
  • 43
  • 63
1

You can't do this without the registry modification.

shfire
  • 837
  • 7
  • 7