6

I have CSS and HTML that I will be converting into PDF. I want to specify a header on each page that, in the PDF, will repeat on each new page.

I know that I can use THEAD to specify the header, however, is there a free html-to-pdf converter that will respect the THEAD tag?

If not, are there any alternatives?

Thanks...

Josh Darnell
  • 11,096
  • 9
  • 36
  • 63
littleK
  • 18,661
  • 27
  • 122
  • 181

5 Answers5

4

Have look at WeasyPrint, it’s open-source and converts HTML/CSS to PDF. (I’m the developer.)

WeasyPrint does repeat <thead> and <tfoot> on each page, but that’s only for tables. For proper page headers, you can use the Paged Media module of CSS3 (supported in WeasyPrint and some other print-oriented engines)

@page { @top-center { content: "My awesome title"; } }

All the details are in the css3-page spec. At some point I want to write more author-friendly documentation for it, but it’s unfortunately not there yet.

Simon Sapin
  • 9,352
  • 2
  • 33
  • 40
4

The open source Flying Saucer xhtmlrenderer html-to-pdf converter respects the THEAD tag since release R8 (April 2009). To repeat the THEAD on every page of PDF output, add the following to your CSS:

        table {
            -fs-table-paginate: paginate;
        }
Eero
  • 4,564
  • 4
  • 35
  • 40
  • when I add the cs -fs-table-paginate: paginate;why my table css :border-collapse:collapse invalid; – FishGel May 09 '12 at 06:37
2

If this is for one time only, perhaps you can simply open the page in a browser and export to PDF from the Print dialog.

This way, the browser deals with correctly displaying the THEAD elements and you get your PDF output.

Daan
  • 6,932
  • 4
  • 27
  • 36
2

I really like Prince XML. It respects thead placement, and supports a lot of CSS. It is free for personal use at least.

Ms2ger
  • 15,180
  • 6
  • 35
  • 35
  • I actually looked into Prince XML a lot, and it is very nice. However, ultimately I would need to purchase a server license ($4000), which is quite a bit. I'm looking for more of an open source alternative. Thanks! – littleK Jul 28 '09 at 12:22
2

For thead to repeat on every page the possible solution is to set it's style to:

@media print {
  thead {
    display: table-header-group;
  }
}

This solves the problem in most browsers, but there is still a problem with dividing table rows on page break, they break in the middle.

Although I do not know if such style is respected in html2pdf converters, there is a possibility to report this requirement to developers of open source converters.

too
  • 2,835
  • 4
  • 33
  • 48