How to deal with page breaks when printing a large HTML table

前端 未结 12 1955
有刺的猬
有刺的猬 2020-11-22 16:44

I have a project which requires printing an HTML table with many rows.

My problem is the way the table is printed over multiple page. It will sometimes cut a row in

12条回答
  •  情深已故
    2020-11-22 17:38

    I recently solved this problem with a good solution.

    CSS:

    .avoidBreak { 
        border: 2px solid;
        page-break-inside:avoid;
    }
    

    JS:

    function Print(){
        $(".tableToPrint td, .tableToPrint th").each(function(){ $(this).css("width",  $(this).width() + "px")  });
        $(".tableToPrint tr").wrap("
    "); window.print(); }

    Works like a charm!

提交回复
热议问题