How to print css using background images using WebBrowser control

I use the webbrowser control in winforms and found that the background images that I use with css are not included in the printouts.

Is there a way to force webbrowser to also print the background of the displayed document?

Edit: Since I wanted to do this programmatically, I chose this solution:

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

Another way to deal with this may be to simply read the value and notify the user about it before typing. I have to agree that setting up using the registry as this is not good practice, so I am open to any suggestions.

Thanks for all your feedback.

+3
source share
5

, , .

, , , .

Registry.LocalMachine

, LocalUser LocalMachine - , ( ), , , .

+1

: HKEY_CURRENT_USER\ \Microsoft\Internet Explorer\PageSetup\Print_Background HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\PageSetup\Print_Background

+2

HKCU : HKEY_CURRENT_USER\ \Microsoft\Internet Explorer\Main\Print_Background

+1

.

Firefox

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

IE

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

Opera

* File > Print Options > Check Off "Print Page Background"
* File > Print Preview (You may have to scroll down/up to see it refresh)
0
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; 
0
source

Source: https://habr.com/ru/post/1696713/


All Articles