Home > Web Front-end > CSS Tutorial > How to Prevent Page Breaks Inside Table Rows When Converting HTML to PDF?

How to Prevent Page Breaks Inside Table Rows When Converting HTML to PDF?

Linda Hamilton
Release: 2024-12-30 16:25:09
Original
795 people have browsed it

How to Prevent Page Breaks Inside Table Rows When Converting HTML to PDF?

Preventing Page Breaks Within Table Rows

In HTML, page breaks inside table rows can become a nuisance when converting to PDF using wkhtmltopdf. While setting page-break-inside: avoid with the table often resolves the issue, it can cease to work with excessive rows.

To overcome this limitation, an alternative CSS approach is available:

<table class="print-friendly">
    <!-- The rest of your table here -->
</table>

<style>
    table.print-friendly tr td, table.print-friendly tr th {
        page-break-inside: avoid;
    }
</style>
Copy after login

Directly applying most CSS rules to tags can alter the table's formatting and introduce double borders. However, and tags within table rows generally allow such CSS specifications. By using the CSS code above, you can apply the page-break-inside: avoid rule to all and descendants within the table designated as class="print-friendly".

The above is the detailed content of How to Prevent Page Breaks Inside Table Rows When Converting HTML to PDF?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template