I have a long table which shows rows on several pages. When a page ends, the row is printed half on one page and half on the next page. How can I make sure that the rows is printed completely on the new page?
Page break for long table
Asked Answered
CSS property: page-break-inside: avoid;
on HTML tr
element does it.
Tested with:
wkhtmltopdf 0.12.3
provided for Linux (Ubuntu Trusty) 32-bit / 64-bit built on Ubuntu 14.04.2
as provided at:
http://wkhtmltopdf.org/downloads.html#stable
A quick and dirty test may look like:
<tr style="page-break-inside: avoid;">
<!-- A little border to see the result more easily -->
<td style="border: solid 1px blue;">
Large text possibly displayed on several pages ...
Large text possibly displayed on several pages ...
Large text possibly displayed on several pages ...
Large text possibly displayed on several pages ...
</td>
<td>col2</td>
<td>col3</td>
</tr>
Thank you, this is also useful if you need to avoid breaking up a div to 2 pages and render the whole div in the next page. –
Dialysis
@Dialysis indeed according to CSS22 spec it should work with block-level elements in general w3.org/TR/CSS22/page.html#page-breaks but in the context of this answer regarding wkhtmltopdf it might be worth testing it is supported by your use case. Would you provide the wkhtmltopdf version you had success with div it would be useful to others. –
Parthenia
Possibly relevant: github.com/wkhtmltopdf/wkhtmltopdf/issues/2182 –
Granger
Will be nice to add this CSS with respective classes
#main_div {
position: relative;
width: 672px; /* find your width in px based on the page margins */
}
tr td {
page-break-before: auto;
page-break-inside: avoid !important;
}
But the most important is to give to your container which contains the table (or some parent div) a fixed width in pixels. Should work for most (WebKit) pdf generators and permit them to calculate correctly the heights.
I can confirm that works for me with wkhtmltopdf 0.12.6 (with patched qt) in kubuntu
© 2022 - 2024 — McMap. All rights reserved.