How to prevent table headings duplicating when generating a PDF


I needed to generate some reports from data we have.

So the first step was to create an HTML page from the data, and then generate a PDF from that HTML that we could send.

So firstly to generate the PDF from the HTML, I used the code in htmlToPdf.js below.

But I was noticing that the table headings would often duplicate themselves. In CSS you can use the @media rule to apply CSS based on the results of a media query. So essentially using

@media print

you can code up CSS that will be only be applied when printing documents. Example in print-media.html below.

The key line of code to prevent table headings duplicating is

thead {display: table-row-group;}

source on Stack Overflow


Leave a Reply

Your email address will not be published.