8

I have seen this similar question.

(I highlighted the important bits to make skim-reading the question faster)

To add to it though, I would like to format an HTML table (with a lot of rows) in such a way that when printed, it would repeat the table headers after each page break. Another words, for the table headers to be visible at the top of each printed page.

Some things I have tried was, when generating the HTML, counting the number of rows, then putting blank rows where I was expecting a page break to occur. At this point I would put in the table headers again.

However, depending on what printer is used, the page breaks end up in different spots. Because each printer seems to have slightly different margin settings, font sizes, etc...

This of course, throws off this whole idea of predicting where a page break will occur.

What strategies do other people use to print HTML tables/forms while maintaining proper formatting?

any ideas?

Community
  • 1
  • 1
7wp
  • 12,505
  • 20
  • 77
  • 103
  • 1
    You might consider providing a PDF version of the table instead. Printing HTML tables is never going to be 'perfect' because of what you mention - margins, and font sizes. – GrandmasterB Sep 02 '10 at 18:11
  • 1
    That has crossed my mind. But I was hoping to do it without that. I once saw a multiple page HTML form on a government website I printed once. This form rendered as one long page on the screen. But when printed from the browser, it formatted perfectly on three pages. with borders on each page. This form was not even a simple html table, instead it was made up of nested tables and divs etc. somehow it all still printed exactly as expected. – 7wp Sep 02 '10 at 18:25
  • It was a secure site, so i could not easily capture the page with all its external CSS and java-script for later viewing. I would have loved to inspect it to find out how they did it. – 7wp Sep 02 '10 at 18:29
  • Can you explain why the answer on the question you linked to is not good enough for you? – Doug Sep 02 '10 at 18:36
  • @Doug I overlooked that detail. I guess this question just became redundant :-) – 7wp Sep 02 '10 at 19:20

1 Answers1

6

Per your own link, posted David Thomas answers it:

On a tangent, it might be worth adding a to your table with the following css thead {display: table-header-group; } so as to print the table-header on all subsequent pages (useful for loooooong data tables). – David Thomas Nov 19 '09 at 14:38

Whats wrong with that solution? Does it not fit the bill?

About table-header-group:

table-header-group (In HTML: THEAD)

Like 'table-row-group', but for visual formatting, the row group is always displayed before all other rows and row groups and after any top captions. Print user agents may repeat header rows on each page spanned by a table. If a table contains multiple elements with 'display: table-header-group', only the first is rendered as a header; the others are treated as if they had 'display: table-row-group'.

Community
  • 1
  • 1
Jakub
  • 20,418
  • 8
  • 65
  • 92