如何在 WebBrowser 控件中打印背景图像和样式

How to print background image and styles in WebBrowser control

我想通过我的 web browser control:

打印背景图片
body {
    background-image: url("image url");
}

为此,我正在生成 html 内容,最后尝试使用以下方法打印文档:

 webBrowserTest.Print();

虽然在运行-时间在浏览器中显示了背景图像,但是在打印时却不打印。如何在打印过程中保留背景图片?

在 Web 浏览器控件和 Internet Explorer 之间共享的 页面设置 对话框中有一个 打印背景颜色和图像 设置。

Microsoft Internet Explorer 的页面设置存储在以下注册表项中:

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup

打印背景颜色和图像 值存储在 Print_Background 键中,可以是 yesno。您可以使用代码更改设置,但请记住,这些值是系统范围的设置,将影响当前用户的 WebBrowser 控件和 Internet Explorer 的所有实例:

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

这是我使用的测试html:

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