Anyname Donotcare
Anyname Donotcare

Reputation: 11393

How to print background image and styles in WebBrowser control

I want to print the background-images through my web browser control:

body {
    background-image: url("image url");
}

To do so, I'm generating the html content and finally try to print the document using:

 webBrowserTest.Print();

While the background image is showing in the run-time in browser, but when printing it does't print. How can I Keep background images during printing?

Upvotes: 1

Views: 1153

Answers (1)

Reza Aghaei
Reza Aghaei

Reputation: 125197

There is a Print Background Colors and Images setting in Page Setup dialog which is shared between Web Browser Control and Internet Explorer.

Page setup settings for Microsoft Internet Explorer are stored in the following registry key:

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup

Print Background Colors and Images value is stored in Print_Background key which can be yes or no. You can change the setting using code, but just keep in mind, these values are system-wide settings and will affect all instances of the WebBrowser control and Internet Explorer for the current user:

using (var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(
    @"Software\Microsoft\Internet Explorer\PageSetup", true))
{
    key.SetValue("Print_Background", "yes", Microsoft.Win32.RegistryValueKind.String);
}

Here is the test html that I used:

<html>
  <head>
    <style>
     body { background-image: url("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"); } 
    </style>
  </head>
  <body>
  </body>
</html>

Upvotes: 2

Related Questions