mPDF Manual – mPDF functions

IndexEntry()

(mPDF ≥ 2.2)

IndexEntry – Insert an Index entry for the document

Description

void IndexEntry ( string $content [ , string $xref ])

Insert an Index entry for the document Index, referencing the current writing position in the document. If $xref is set, it will appear as a cross-referencing entry in the index as for IndexEntrySee().

Parameters

$content

This parameter sets the text as it will appear in the Index entry.

$content cannot contain any of the characters: <, >, &, ' or " and must use the appropriate HTML entities e.g. <annotation content="This is &amp;lt; 40" />

It is recommended that you use htmlspecialchars('Content', ENT_QUOTES) for this.

Text entries passed in the form Subject:Subcategory will appear in the Index as “Subject, Subcategory”

REQUIRED

$xref

This parameter sets the text used as a cross-reference. Text should be UTF-8 encoded.

$xref cannot contain any of the characters: <, >, &, ' or " and must use the appropriate HTML entities e.g. <indexentry xref="&amp;lt; 40" />

It is recommended that you use e.g. htmlspecialchars($xref, ENT_QUOTES) for this.

Text entries passed in the form Subject:Subcategory will appear in the Index as “Subject, Subcategory”

OPTIONAL

Changelog

Version Description
3.0 $xref parameter added.

Examples

Example #1

<?php
$mpdf = new \Mpdf\Mpdf();

$mpdf->WriteHTML('
Beginning bit of document...
');

$mpdf->IndexEntry("Buffalo");
$mpdf->WriteHTML('
Your text which refers to a buffalo, which you would like to see in the Index
');

$mpdf->AddPage();
$mpdf->WriteHTML('<h2>Index</h2>', \Mpdf\HTMLParserMode::HTML_BODY);
$mpdf->CreateIndex(2, '', '', 3, 1, '', 5, 'serif','sans-serif');

$mpdf->Output();

Example #2

<?php
$mpdf->IndexEntry("Dromedary", "Camel:types");

// This will produce an entry in the Index under 'Dromedary' appearing as:

Dromedary - see Camel, types

Notes

Recommended placement of Index Entries is just after the first word following the opening tag of the block element:

<h2>First<indexentry... /> word of a heading or block</h2>

or alternatively just after the opening tag of the block element:

<h2><indexentry... />Heading or block</h2>

or just after a word to be marked:

... this is a word<indexentry... /> in the middle of text to be marked ...

See Also

Fork me on GitHub