mPDF Manual – What Else Can I Do

# Index

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):

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

A default stylesheet for Indexes is included in mpdf.css

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

A

Alonso, Fernando

Ãlvarez, Isaac

Arroyo Molino, David

B

BenÃtez, 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.:

• or -

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.

You can see which Locales are available on your (Unix) system: &lt;?php system('locale -a') ?&gt;

Note: Index collation will probably not work on Windows servers because of the problems setting Locales under Windows.

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:

• or -

Values should be selected from the available file names in folder /collations/.

Note: This will not affect the overall order of entries, which is determined by the value of “collation”.

Note: The groupings do not always match the order set by locale. This is because the data for collations has come from different sources. The files in /collations/ can be edited.

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

Note: htmlspecials_encode should be used to encode the text of content in <indexentry> - although not when using IndexEntry().

### Columns

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

### Index Sub-entries

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

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 $this->indexUseSubentries in config.php. This is the default appearance, with$this->indexUseSubentries = false; - Mammals 73 - elephants 142 - humans 173 Marsupials - kangaroos 75 - wombats 86 Index entries can also include simple mark-up tags and/or more than one colon e.g: which appears as: Mammals - **elephants**: breeding 15 This is the appearance with \$this->indexUseSubentries = false; Mammals 73 Mammals, elephants 142 Mammals, **elephants**: 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.