2

I am trying to avoid having page breaks inside of rows for my HTML tables that may go past one page. I am using Internet Explorer Print Preview and also BCL EasyPDFSDK to convert to PDF to test this. I applied the following CSS styling in various combinations to the <td> elements but for each one I was getting an undesired result:

td {
    page-break-inside: avoid !important;
    white-space: nowrap;
    overflow: hidden;
    margin: 4px 0 4px 0;
}

I believe the page-break-inside: avoid !important is working, but only on the <td> level. For example, I will see a <tr> that has one <td> on the end of the first page with all of the text intact, but the following <td> tags would be on the next page with all of their text intact.

I didn't think you were supposed to apply formatting to <tr> so I'm unsure how to go about fixing this.

Should I apply the CSS to the <tr> or is there another way to achieve this?

Thanks for the help!

Ibrennan208
  • 1,345
  • 3
  • 14
  • 31

2 Answers2

7

Turns out I needed to collapse borders on the table element and reduce my padding to only 1px using

table { border-collapse: collapse; }
td {
    page-break-inside: avoid !important;
    white-space: nowrap;
    overflow: hidden;
    padding: 1px;
    font-size: xx-small;
}

I also set the font-size to xx-small just in case that was causing an issue. The issue seemed to primarily be resolved when I collapsed borders, so it makes me wonder if the table was having issues splitting the rows because of that.

Cheers!

EDIT:

Since dealing with this issue, I have found out that the row splitting is handled much better in newer web browsers. I highly recommend updating IE to at least 11 if you are experiencing this issue.

Ibrennan208
  • 1,345
  • 3
  • 14
  • 31
-1

I just added the below css to my @media print and it worked!!!

None of the solutions applied to td, th, tr worked

table {
  page-break-inside: avoid !important;
}
Binesh
  • 1
  • This doesn't seem to answer the question asked. The question implies a table that cannot fit on a single page, so you do want some breaks within a table; you just want them at row boundaries. – Sam Hartman Nov 27 '21 at 18:49