0

I have a view with a long HTML table. When I try to print that view, the table gets divided into several pages. Obviously, the table breaks and continues to next page and so on. I want to be able to add a header and a footer on EACH of these print pages neatly.

I have tried using css page break properties like:

page-break-inside page-break-after page-break-before

I have tried fixing the header and footer to top and bottom using position: fixed. Even if the footer shows on every page it overlaps the table.as you can see in highlighted area:

enter image description here

So I want to display the header and footer without any overlapping.

Table breaking

This is how the table breaks^^

I want a header and footer to show on every page. I tried adding my header and footer in the thead and tfoot tag but that didnt work.

I have tried using css page break properties like:

page-break-inside page-break-after page-break-before

I have tried fixing the header and footer to top and bottom using position: fixed. Even if the footer shows on every page it overlaps the table.as you can see in highlighted area:

Zach Jensz
  • 3,650
  • 5
  • 15
  • 30
Ahmed Fiaz
  • 11
  • 3
  • Does this answer your question? [How to use HTML to print header and footer on every printed page of a document?](https://stackoverflow.com/questions/1360869/how-to-use-html-to-print-header-and-footer-on-every-printed-page-of-a-document) – K i Feb 24 '23 at 09:49
  • No tried and tested. That didnt work – Ahmed Fiaz Feb 24 '23 at 09:51
  • Sorry i was referring to this https://stackoverflow.com/a/7197225/11196771, CSS3 and HTML5 don't support this yet – K i Feb 24 '23 at 09:52
  • Chrome certainly intends to obey https://www.w3.org/TR/css-tables-3/#repeated-headers. Please share your code that is not working for you. – dgrogan Mar 01 '23 at 22:44
  • @dgrogan @K i, Thanks guys but I soled the issue. Please take a look at the answer below – Ahmed Fiaz Mar 03 '23 at 10:24

1 Answers1

1

Here is the code that solved my issue:

HTML

<table>
  <thead><tr><td>
    <div class="header-space">&nbsp;</div>
  </td></tr></thead>
  <tbody><tr><td>
    <div class="content">...</div>
  </td></tr></tbody>
  <tfoot><tr><td>
    <div class="footer-space">&nbsp;</div>
  </td></tr></tfoot>
</table>
<div class="header">...</div>
<div class="footer">...</div>

CSS

.header, .header-space,
.footer, .footer-space {
  height: 100px;
}
.header {
  position: fixed;
  top: 0;
}
.footer {
  position: fixed;
  bottom: 0;
}
Chris Barr
  • 29,851
  • 23
  • 95
  • 135
Ahmed Fiaz
  • 11
  • 3