如何在WebBrowser控件中打印背景图像和样式 [英] How to print background image and styles in WebBrowser control

查看:52
本文介绍了如何在WebBrowser控件中打印背景图像和样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过我的网络浏览器控件:

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

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

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?

推荐答案

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

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

Microsoft 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 键中,该键可以是 yes no .您可以使用代码来更改设置,但请记住,这些值是系统范围的设置,并且会影响 WebBrowser 控件和当前用户的Internet Explorer的所有实例:

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);
}

这是我使用的测试html:

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>

这篇关于如何在WebBrowser控件中打印背景图像和样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆