Cómo imprimir imágenes de fondo aplicadas CSS con control WebBrowser
-
09-06-2019 - |
Pregunta
Estoy usando el control del navegador web en Winforms y descubrí que las imágenes de fondo que aplico con CSS no están incluidas en las impresiones.
¿Hay alguna manera de hacer que el navegador web también imprima el fondo del documento mostrado?
Editar:Como quería hacer esto programáticamente, opté por esta solución:
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);
Otra forma de manejar esto podría ser simplemente leer el valor y notificar al usuario que lo ajuste él mismo antes de imprimir.Tengo que aceptar que modificar el registro de esta manera no es una buena práctica, por lo que estoy abierto a cualquier sugerencia.
Gracias por todos tus comentarios
Solución
Si va a cambiar una configuración importante del sistema, asegúrese de leer primero la configuración actual y restaurarla cuando haya terminado.
Considero esto muy mal Practica en primer lugar, pero si debes hacerlo, entonces sé amable.
Registry.LocalMachine
Además, intenta cambiar LocalUser
en lugar de LocalMachine
- de esa manera, si tu aplicación falla (y lo hará), solo confundirás al usuario, no a todos los que usan la máquina.
Otros consejos
Otra clave de registro sería:HKEY_CURRENT_USER Software Microsoft Internet Explorer PageSetup Print_Background Hkey_local_machine Software Microsoft Internet Explorer PageSetup Print_Background
La clave HKCU correspondiente para esta configuración es:HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Print_Background
De forma predeterminada, el navegador no imprime ninguna imagen de fondo.
En Firefox
* File > Page Setup > Check Off "Print Background"
* File > Print Preview
En IE
* Tools > Internet Options > Advanced > Printing
* Check Off "Print Background Images and Colors"
en la ópera
* 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;