openhtmltopdf icon indicating copy to clipboard operation
openhtmltopdf copied to clipboard

Avoid empty header/footer rows on new page in openhtmltopdf?

Open spreddy2714 opened this issue 3 years ago • 0 comments

I am using openhtmltopdf to generate paginated tables rendering in a pdf document, Below template rendering extra header and footer in an additional page, which shouldn't be, as there are no more rows left.


 <html>

<head>
    <style>
        @page {
            size: 400px 350px;
        }

        table {
            width: 100%;
            font-size: 16px;
            border-collapse: collapse;

            /* The magical table pagination property. */
            -fs-table-paginate: paginate;

            /* Recommended to avoid leaving thead on a page by itself. */
            -fs-page-break-min-height: 1.5cm;
        }

        tr,
        thead,
        tfoot {
            page-break-inside: avoid;
        }

        td,
        th {
            padding: 6px;
            border: 1px solid gray;
        }

        tfoot td {
            background-color: aqua;
        }

        thead th {
            background-color: coral;
        }
    </style>
</head>

<body>
    <table>
        <caption>
            <p>This example shows how to use table pagination.</p>
            <p>The table header and footer are automatically reproduced on each page.</p>
        </caption>

        <thead>
            <tr>
                <th>Title 1</th>
                <th>Title 2</th>
            </tr>
        </thead>

        <tbody>
            <tr>
                <td>Hello</td>
                <td>World!</td>
            </tr>
            <tr>
                <td>Hello</td>
                <td>World!</td>
            </tr>

        </tbody>

        <tfoot>
            <tr>
                <td>Footer 1</td>
                <td>Footer 2</td>
            </tr>
        </tfoot>
    </table>
</body>

</html>

Below is the output it is rendering

image

spreddy2714 avatar Jan 24 '22 06:01 spreddy2714