Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS to PDF, using THEAD for repeating header on new page

Tags:

html

css

pdf

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...

like image 694
littleK Avatar asked Jul 27 '09 19:07

littleK


3 Answers

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;
        }
like image 75
Eero Avatar answered Sep 25 '22 06:09

Eero


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.

like image 36
Simon Sapin Avatar answered Sep 23 '22 06:09

Simon Sapin


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.

like image 34
Daan Avatar answered Sep 21 '22 06:09

Daan