Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

page-break-after does not work in Chrome

I have a problem with page-break-after in Google Chrome during printing. It seems that it's not working. I tried Firefox and it's ok there. My code is:

<div style="position: relative; display: block;">

    <div style="display: block; page-break-after: always; position: relative;">Page 1</div>

    <div style="display: block; position: relative; page-break-before:always;">Page 2</div>

</div>

Is there any trick to get it done in Chrome?

like image 426
Deathlex Avatar asked Mar 08 '16 15:03

Deathlex


3 Answers

It should not be inside a flex div. If it is, page break does not work unless flex div is closed.

Ex:

   <div class="row">
           //bla bla    
   </div>/*close old flex div*/
    <div class="col-12 p-0 display-block break-before"></div>
    <div class="row">/*new flex div*/
              //bla bla
    </div>
    <style>
    .break-before {
        display: block;
        position: relative;
        page-break-before: always !important;   
    }
    </style>
like image 161
Hakan Avatar answered Nov 13 '22 14:11

Hakan


Please note for page-break to work, div should not have any float!

So if your div has say float:left , reset it for print saying: float: none and it will make page break work again.

like image 37
Mohsin Avatar answered Nov 13 '22 14:11

Mohsin


It is a hack, but Chrome doesn't support page-breaks very well. So try to use this instead:

<body>
    <main role="main">
        <section class="tabs">
            <div class="tabbed-content">
                <div class="break-after">Page 1</div>
                <div class="break-before">Page 2</div>
            </div>
        </section>
    </main>
</body>

And add this to your css:

html, body, .main, .tabs, .tabbed-content { float: none; }

.break-after {
    display: block;
    page-break-after: always;
    position: relative;
}

.break-before {
    display: block;
    page-break-before: always;
    position: relative;
}
like image 11
M Zeinstra Avatar answered Nov 13 '22 15:11

M Zeinstra