Problem unpacking page while printing using javascript - Chrome, Firefox, IE9 and higher

I have an application that prints an html table using window.print(). The application works fine when I click on the hyperlink to print, the problem I encountered is page break, I studied and found many solutions, most of them use css to solve the problem, but when I tried css as below, it does not work. Sample demo I made fun of in JS-Fiddle to show the problem

Test it in chrome to preview it and use A4 page size to view page breaks.

enter image description here

Jsfiddle

@media print {
    body * {
        visibility: hidden;
    }
    div {
        page-break-inside: avoid;
    }
    table {
        page-break-after: always;
        page-break-inside: auto;
    }
    tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }
    td {
        page-break-inside: avoid;
        page-break-after: auto;
    }
    thead {
        display: table-header-group;
    }
    tfoot {
        display: table-footer-group;
    }

    #printSection * {
        visibility: visible;
    }
    #printSection {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        margin: 0 auto;
        width: 100%;
    }
}
+4
3

jsfiddle.net/w2p5kbcj/14

CSS

@media screen {
    #printSection {
        display: none;
    }
}
@media print {
    table {
        page-break-after: auto;
        page-break-inside: auto;
        width:100%;
        border-width: 1px solid #000;
        font-size:16px;
        font-family:Arial;
    }

     td{
        padding:2px 5px 2px 5px;
    }

}

HTML

Javascript

https://github.com/AAverin/JSUtils/blob/master/wkhtmltopdfTableSplitHack/wkhtmltopdf_tableSplitHack.js

js splitForPrint , .

+1
@media print {
  .page-break  { display: none; page-break-before: avoid; }
}

, .

<div class="page-break"></div>
+1

. , , table div s.

, div > div > div table > tr > td css :

div(style: display: table;)
    > div(style: display: table-row;)
        > div(style: display: table-cell;)

: page-break-after: always;. Chrome . , .


2

( , , ), media print , :

@media print {
    div > div {
        display: block;

        > div {
              display: inline-block;
        }
    }
}

div .table , . : https://github.com/nikoloza/Scratch/blob/master/scratch/less/core/classes.less#L83

0

All Articles