How to avoid pagination within table rows
P粉529245050
2023-08-20 20:24:22
<p>I want to avoid pagination within table rows via wkhtmltopdf when converting HTML to PDF. I used page-break-inside:avoid with table and it worked, but not when there are many rows.
If the display is set to block or other methods, the format of the table will be changed and double borders will be inserted.
Or you can insert a table header on each page to display when the table is split. </p>
The best way I've found to handle this in webkit browsers is to place a div inside each td element and apply the page-break-inside: avoid style to the div like this:
Although Chrome reportedly does not recognize the 'page-break-inside: avoid;' attribute, this appears to prevent line content from being split in half by page breaks when generating PDFs using wktohtml. The tr element may break slightly beyond the page, but the div and anything inside it will not.
You can try to use CSS:
Most CSS rules cannot be applied directly to
<tr>
tags because as you pointed out above - they have uniquedisplay
styles that do not allow these CSS rules. However, the<td>
and<th>
tags usually allow for this specification - you can easily apply these rules to all children using the CSS in the example above ##<tr>and
<td>.