mPDF Manual – Headers & Footers

# Headers & Footers

Page headers and page footers can be set for mPDF documents in a number of different ways. As mPDF has evolved, new methods have been added.

## Types

RUNTIME - RUNTIME headers/footers are set as they are required throughout the document.

NAMED - NAMED headers/footers are defined at any time (before they are used) and given a ‘name’; they can then be used/re-used by reference to that name at any time. They can be defined by either PHP script or custom HTML tags.

Non-HTML - NON-HTML headers/footers are set by text strings with no HTML mark up to define styles. Style changes (font-size, font-family, color) can be defined by changing mPDF variables.

HTML - HTML headers/footers are written in standard HTML code. They can only be defined outside HTML block tags (except <body>).

## Methods

 NON-HTML HTML RUNTIME **Method 1** *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 for ODD and EVEN pages. Style can be defined by variables: $defaultheaderfontsize$defaultheaderfontstyle $defaultheaderline$defaultfooterfontsize $defaultfooterfontstyle$defaultfooterline **Method 2** *T**he simplest & quickest way to program a header/footer once for the whole document that includes images or uses more complex layout styles.* SetHTMLHeader() SetHTMLFooter() NAMED Define **Method 3** *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() **Method 4** *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() Reference *These methods are recommended when setting the header/footer at the start of a document. * SetHeaderByName() SetFooterByName() @page *These methods are recommended when setting the header/footer at the start of a document.* SetHTMLHeaderByName() SetHTMLFooterByName() @page *Recommended when you wish to change the headers/footers during the document.* These methods can reference any NAMED header or footer (NON-HTML or HTML) AddPage() TOCpagebreak() @page

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 php date() function.