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

问题描述 投票:1回答:1

我想通过我的web browser control打印背景图像:

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

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

 webBrowserTest.Print();

尽管背景图像在浏览器中正在运行时显示,但是在打印时不会打印。如何在打印过程中保留背景图像?

c# html .net winforms webbrowser-control
1个回答
1
投票

页面设置对话框中的有打印背景色和图像]设置,该设置在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>

© www.soinside.com 2019 - 2024. All rights reserved.