mPDF Manual – What Else Can I Do


mPDF can generate an index at the end of document using:

  • <indexentry content="Buffalo" /> to make index entries at the appropriate place in the HTML text
  • <indexinsert ... /> generates and inserts the Index at the end of document
  • <indexentry> or IndexEntry() should be used to create Index entries during document writing.
  • <indexinsert> or InsertIndex() should be used to generate the Index at the end of the document.

When an Index is inserted in the PDF document using <indexinsert> or InsertIndex(), the Index is generated (internally) as HTML code in the following format (with the markup as shown):

<div class="mpdf_index_main">
    <div class="mpdf_index_letter">A</div>
    <div class="mpdf_index_entry">
        Aardvark<a class="mpdf_index_link" href="#page37">37</a>

CSS stylesheets can thus be used to control the layout of the Index e.g.:

/* For Index */

div.mpdf_index_main {
    line-height: normal;
    font-family: sans-serif;

div.mpdf_index_letter {
    line-height: normal;
    font-family: sans-serif;
    font-size: 1.8em;
    font-weight: bold;
    text-transform: uppercase;
    page-break-after: avoid;
    margin-top: 0.3em;
    margin-collapse: collapse;

div.mpdf_index_entry {
    line-height: normal;
    font-family: sans-serif;
    text-indent: -1.5em;

a.mpdf_index_link {
    color: #000000;
    text-decoration: none;

A default stylesheet for Indexes is included in [mpdf root]/data/mpdf.css. (Custom defaults file could be set by the defaultCssFile configuration setting)

Index Collation

In order to generate an Index with non-ASCII characters, entries need to be sorted accordingly (collation), and non-ASCII characters should map to the appropriate Dividing letter e.g.:


Alonso, Fernando Ãlvarez, Isaac Arroyo Molino, David


Benitez, Carlos

Entries in an Index can now be sorted using any of the Locale values available on your system. Set it using the “collation” property/parameter e.g.:

<indexinsert usedivletters="on" links="off" collation="es_ES.utf8"
    collation-group="Spanish_Spain" />


$mpdf->InsertIndex(true, false, "es_ES.utf8", "Spanish_Spain");

NB You should always choose a UTF-8 collation, even when you are using Core fonts or e.g. charset-in="win-1252", because mPDF handles all text internally as UTF-8 encoded.

If you have set your index to use Dividing letters, you can also determine how letters are grouped under a dividing letter. In the example index above, we want à to be grouped under the letter a/A. Set the “collation-group” using:

<indexinsert usedivletters="on" links="off" collation="es_ES.utf8"
    collation-group="Spanish_Spain" />


$mpdf->InsertIndex(true, false, "es_ES.utf8", "Spanish_Spain");

Values should be selected from the available file names in directory [mpdf root]/data/collations/.

The array consists of [index]: unicode decimal value of character => unicode decimal value of character to group under: e.g. Ã [A tilde] (U+00C3) (decimal 195) => a (U+0061) (decimal 97). The target character should always be the lowercase form.

Non-ASCII chcracters in Index entries


From mPDF 6.0, columns are not specified as part of the <indexinsert>, so a typical 2-column index might be produced by:


<columns column-count="2" column-gap="5" />

<indexinsert usedivletters="on" links="on" collation="en_US.utf8"
    collationgroup="English_United_States" />

<columns column-count="1" />

Index Sub-entries

Index entries can contain sub-entries, separated by colons e.g.

<indexentry content="Mammals:elephants" />

A shorthand way of displaying subentries is set by default, which suppresses the main entry if > 1 subEntry. It can be disabled/enabled using the configurable variable indexUseSubentries in config constructor parameter.

This is the default appearance, with

$this->indexUseSubentries = false;

Mammals 73

- elephants 142
- humans 173


- kangaroos 75
- wombats 86

Index entries can also include simple mark-up tags and/or more than one colon e.g:

<indexentry content="Mammals:&lt;b&gt;elephants&lt;/b&gt;: breeding" />

which appears as:


- <b>elephants</b>: breeding 15

This is the appearance with

$this->indexUseSubentries = false;

Mammals 73
Mammals, elephants 142
Mammals, <b>elephants</b>: breeding 15
Mammals, humans 173
Marsupials, kangaroos 75
Marsupials, wombats 86

Customised appearance (advanced)

Several variables set at beginning of function InsertIndex() in mpdf.php which could be changed to alter appearance of Index. e.g. spacer, and joiner characters.

Fork me on GitHub