Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing bootstrap 4 HTML page in Chrome cuts off chrome header/footers

I have an issue with printing an HTML page styled with Bootstrap 4 (only 4, 3.3.7 works fine) from Chrome where the header and footer are partly covered up. Here is a screenshot of what I'm referring to, you'll see the date, title, file/url are partly cut off. It seems be an issue with bootstrap. I created a small test page with nothing but a link to the bootstrap cdn and it still happens.

Here is the HTML as a test:

<html>
    <head>
        <link rel="stylesheet"
            href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" 
            integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" 
            crossorigin="anonymous">
    </head>
    <body>
    </body>
</html>

If you put that into an html page and then open it in chrome and right-click -> print, you should see the same results.

Any ideas how to fix?

like image 747
Geo Avatar asked Apr 11 '18 22:04

Geo


2 Answers

The issue seems to be that the size property is set to a3 in the full bootstrap css file (not the grid or reboot) in version 4.1.1 (most recent version at time of writing)

to fix add following snippet:

@page {
    size: auto;
}
like image 72
pawel Avatar answered Sep 28 '22 06:09

pawel


Rather than include an additional @page { size: auto; } rule override the $print-page-size: auto; variable before importing the bootstrap scss file:

https://getbootstrap.com/docs/4.0/getting-started/theming/#variable-defaults

like image 41
Mike Avatar answered Sep 28 '22 06:09

Mike