mPDF Manual – HTML control tags

tocentry

(mPDF >= 1.0)

tocentry – Insert an entry for the Table of Contents

Description

<tocentry  $content [ $level ] [ $name ] />

Insert an entry for the Table of Contents referencing the current writing position in the document.

Parameters

$content

This parameter sets the text as it will appear in the ToC entry. Text should be UTF-8 encoded.

$content cannot contain any of the characters: < > & ‘ or “ and must use the appropriate HTML entities e.g. <tocentry content=”&lt; 40” />

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

REQUIRED

$level

Specify the level of this entry (i.e. like heading 1,2,3) as a positive integer 

Starts at level 0

DEFAULT: 0

$name

Specify which ToC to add this entry, if using more than one ToC in the document. $name can be any alphanumeric characters (except just “0”) and is case-insensitive.

BLANK or omitted or 0 uses the default ToC.

Values (case-insensitive)

“ALL” will add this entry to every ToC active in the document.

Changelog

VersionDescription
2.3 $name attribute was added.

Examples

Example #1

<?php

$mpdf = new mPDF();

$mpdf->WriteHTML('Introduction');

$mpdf->WriteHTML('<tocpagebreak />');

$mpdf->WriteHTML('<tocentry content="Chapter 1" />');

$mpdf->WriteHTML('Chapter 1 ...');

$mpdf=Output();

?>

Notes

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

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

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

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

or just after a word to be marked:

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

See Also