background image does not print (using window.print)

0

I need to print a page that has a background image as a background, a logo on a watermark.

But using window.print () the background does not appear in the frame (unless the user checks "background graphics" on the print page in chrome.

I searched and found a line of code in css that forces the chrome to print the background color, but I do not find the code that forces the image to print.

Page code:

   <html lang="pt-BR">
            <link href="css/impressao.css" rel="stylesheet" type="text/css">
            <script type="text/javascript" src="js/main.js"></script>
        </head>
        <body>
            <script type="text/javascript">
                window.print();
                window.location.href = '../home.php';

            </script>
        </body>
    </html>

CSS:

body{
    background-image: url(../img/MARCA.png);
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-position: center;
}

Ps. I have synthesized the code only for the part that is relevant to the question, to facilitate understanding.

Can anyone help?

    
asked by anonymous 02.04.2018 / 14:06

1 answer

0

In Chrome and Safari you can add the CSS rule:

-webkit-print-color-adjust: exact;

This will force the browser to print the background colors and images.

Source: link

    
02.04.2018 / 20:29