Force browser to print background graphics using CSS in ASP.Net

madawak
 
on Jul 26, 2021 11:13 PM
Sample_607315.zip
10541 Views

Hi,

Does anyone know how to override browser background graphics settings when printing in ASP.Net/CSS.

If the browser background graphics is not enabled/ticked on user's web browser(i.e on Chrome) when a user prints the web page, I would like to override this setting and enable/tick browser background graphics.

Thanks.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Jul 28, 2021 06:18 AM

Hi madawak,

The -webkit-print-color-adjust property is a non-standard CSS extension that can be used to force printing of background colors and images in browsers based on the WebKit engine.

This forces browsers to use background colors when user prints a web page even if they have Print Options Background Graphics turned off.

economy (Default value)

Normal behavior. Background colors and images are only printed if the user explicitly allows it in their browser's print settings dialog.

exact

Background colors and images of the element to which this rule is applied are always printed, user's print settings are overridden.

Syntax

-webkit-print-color-adjust: exact;

Example

<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style>
        #dvHtml {
            background-color: #123456 !important;
        }

        @media print {
            body {
                -webkit-print-color-adjust: exact;
                -moz-print-color-adjust: exact;
                -ms-print-color-adjust: exact;
                print-color-adjust: exact;
            }
        }
    </style>
</head>
<body>
    <div style="height:100%" id="dvHtml">
        Test
        <br /><br /><br /><br /><br />
    </div>
</body>
</html>