打印大型 HTML 表格时如何处理分页符 [英] How to deal with page breaks when printing a large HTML table

查看:53
本文介绍了打印大型 HTML 表格时如何处理分页符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目需要打印一个多行的 HTML 表格.

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 half, making it unreadable because one half is on the bleeding edge of a page and the remainder is printed on the top of the next page.

我能想到的唯一可行的解​​决方案是使用堆叠的 DIV 而不是表格,并在需要时强制分页......但在完成整个更改之前,我想我可以先在这里问一下.

The only plausible solution I can think of is using stacked DIVs instead of a table and force page-breaks if needed.. but before going through the whole change I thought I could ask here before.

推荐答案

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test</title>
<style type="text/css">
    table { page-break-inside:auto }
    tr    { page-break-inside:avoid; page-break-after:auto }
    thead { display:table-header-group }
    tfoot { display:table-footer-group }
</style>
</head>
<body>
    <table>
        <thead>
            <tr><th>heading</th></tr>
        </thead>
        <tfoot>
            <tr><td>notes</td></tr>
        </tfoot>
        <tbody>
        <tr>
            <td>x</td>
        </tr>
        <tr>
            <td>x</td>
        </tr>
        <!-- 500 more rows -->
        <tr>
            <td>x</td>
        </tr>
    </tbody>
    </table>
</body>
</html>

这篇关于打印大型 HTML 表格时如何处理分页符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆