addHeader

addHeader

TRIAL / ADVANCED / PREMIUM

Inserts headers into the Word document.

Description
public addHeader ( array $headers )

It is possible to include a different header for:

  • the first page or title page.
  • even pages.
  • odd pages (this one is the default header for the whole document if no other headers are defined for the first or even pages).

The contents of the different headers are defined via the use of WordFragments. These header WordFragments allow for the insertion of:

  • text paragraphs
  • current date and/or hour
  • images
  • links
  • lists
  • page numbers
  • shapes
  • tables
  • HTML content
  • ...

You may also import the headers of an existing DOCX document via the ImportHeadersAndFooters method.

This method adds new headers into all sections, removing existing headers. The addHeaderSection method allows adding headers per section.

Parameters

headers

An array with the different header contents.

Key Type Description
default WordFragment The WordFragment object containing the contents for the default (odd pages) header.
even WordFragment The WordFragment object containing the contents for the even pages header.
first WordFragment The WordFragment object containing the contents for the first (title) page header.
Exceptions

Not using WordFragments.

Code samples

Example #1:

The resulting Word document looks like this:

Example #2:

The resulting Word document looks like this: