Page headers and page footers can be set for mPDF documents in a number of different ways. As mPDF has evolved, newmethods have been added.
Warning: Use of CSS @page selector with any content will rewrite/remove headers not defined in the selector. See@page selector documentation.
Note: As from mPDF v6.0 Headers and Footers are all now written internally as HTMLheaders/footers.
Theuse of non-HTML headers and footers (methods 1 & 3) is deprecated, but remains supported. Non-HTML headers and footers are converted in mPDF to HTML equivalents.
Default non-HTML headers will not clash with HTML headers, but named non-HTML headers WILL clash with (and overwrite) HTML headers of the same (equivalent) name e.g.MyFooter (non-HTML)overwriteshtml_MyFooter (HTML).
Note: As from mPDF v7.1 Headers and Footers supportabsolute positioning, howeveryou cannot use both absolute and non-absolute positioned content together in the Headers and Footers.
<body>).Note:HTML headers/footers are more intensive of processing time and memory. This probably makes little difference for an average/short document, but may be important for long/complex documents.
| NON-HTML | HTML | ||
| RUNTIME | Method 1 (deprecated) This is the simplest & quickest way to define a header/footer for the whole document if you need limited control over styling. SetHeader()SetFooter() There are several variants of this method, using string or array. The simplest form does not allow different header/footer forODD andEVEN pages. Style can be defined by variables: $defaultheaderfontsize$defaultheaderfontstyle$defaultheaderline$defaultfooterfontsize$defaultfooterfontstyle$defaultfooterline | The simplest & quickest way to program a header/footer once for the whole document that includes images or uses more complex layout styles. | |
| NAMED | Define | Method 3 (deprecated) This method is useful if you do not need the flexibility of an HTML header/footer, but are changing headers/footers throughout the document. DefHeaderByName()DefFooterByName() <pageheader> <pagefooter> | This is the best way for complex headers/footers with the advantage of HTML code, but you can easily change the headers/footers at any time during the document. DefHTMLHeaderByName()DefHTMLFooterByName() <htmlpageheader> <htmlpagefooter> |
| Reference | These methods are recommended when setting the header/footer at thestart of a document. SetHeaderByName()SetFooterByName() <setpageheader> <setpagefooter>@page | These methods are recommended when setting the header/footer at thestart of a document. SetHTMLHeaderByName()SetHTMLFooterByName() <sethtmlpageheader> <sethtmlpagefooter>@page | |
Recommended when you wish to change the headers/footersduring the document. These methods can reference anyNAMED header or footer (NON-HTML orHTML) | |||
In any of the options,{PAGENO} or{DATE j-m-Y} can be used - which will be replaced by the page number or current date.j-m-Y can be replaced by any of the valid formats used in the PHPdate() function.
Method 4 NAMED HTML headers & footers