我正在 winforms 中使用 webbrowser 控件,现在发现我使用 css 应用的背景图像不包含在打印输出中。

有没有办法让网络浏览器也打印显示文档的背景?

编辑:由于我想以编程方式执行此操作,因此我选择了以下解决方案:

using Microsoft.Win32;

...

RegistryKey regKey = Registry.CurrentUser
                    .OpenSubKey("Software")
                    .OpenSubKey("Microsoft")
                    .OpenSubKey("Internet Explorer")
                    .OpenSubKey("Main");

//Get the current setting so that we can revert it after printjob
var defaultValue = regKey.GetValue("Print_Background");
regKey.SetValue("Print_Background", "yes");

//Do the printing

//Revert the registry key to the original value
regKey.SetValue("Print_Background", defaultValue);

处理此问题的另一种方法可能是仅读取该值,并通知用户在打印之前自行调整该值。我必须同意,像这样调整注册表并不是一个好的做法,因此我愿意接受任何建议。

感谢您的所有反馈

有帮助吗?

解决方案

如果您要更改重要的系统设置,请确保首先读取当前设置并在完成后恢复它。

我认为这个 很坏 首先要练习,但如果你必须这样做,那就要友善。

Registry.LocalMachine

另外,尝试改变 LocalUser 代替 LocalMachine - 这样,如果您的应用程序崩溃(并且它会崩溃),那么您只会让用户感到困惑,而不是让每个使用该机器的人感到困惑。

其他提示

另一个注册表项是:HKEY_CURRENT_USER SOFTWORD MICROSOFT Internet Explorer pagesetup print_background hkey_local_machine Software Microsoft Microsoft Internet Explorer pagesetup print_background

此设置对应的 HKCU 键为:HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Print_Background

默认情况下,浏览器根本不打印背景图像。

在火狐浏览器中

* File > Page Setup > Check Off "Print Background"
* File > Print Preview

在IE中

* Tools > Internet Options > Advanced > Printing
* Check Off "Print Background Images and Colors"

在歌剧中

* File > Print Options > Check Off "Print Page Background"
* File > Print Preview (You may have to scroll down/up to see it refresh)
var sh = new ActiveXObject("WScript.Shell");
key = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\Main\\Print_Background";
var defaultValue = sh.RegRead(key); 
sh.RegWrite(key,"yes","REG_SZ");
document.frames['detailFrame'].focus(); 
document.frames['detailFrame'].print();
sh.RegWrite(key,defaultValue,"REG_SZ");  
return false; 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top