mPDF Manual – mPDF functions

TOCpagebreakByArray()

(mPDF ≥ 5.0)

TOCpagebreakByArray — Insert a table of contents in the document using an array of parameters

Description

void TOCpagebreakByArray ([ array $arr ])

Add a new page to the document using an array of (optional) parameters, marking the point at which a Table of Contents (ToC) will be inserted in the document at the end of writing. The numerous parameters specify both paging details for the continuing document, and for the ToC when it is generated.

Parameters

The initial parameters specify characteristics for the ToC, which is generated automatically at the end of the document when Output() is called.

$paging = true | 1 | false | 0

Specify whether to show page numbers in the ToC.

BLANK or omitted uses a default value of true.

Default: true

Values

true or 1
show page numbers in the ToC.
false or 0
do not show page numbers in the ToC.
$links = true | 1 | false | 0

Specify whether to generate hyperlinks in the ToC.

BLANK or omitted uses a default value of false.

Default: false

Values

true or 1
show hyperlinks in the ToC.
false or 0
do not show hyperlinks in the ToC.
$toc-orientation

This attribute specifies the orientation of the ToC pages.

BLANK or omitted leaves the orientation unchanged i.e. at the end of the document (before the ToC is generated)

Values (case-insensitive)

'L' or 'landscape'
Landscape
'P' or 'portrait'
Portrait
toc-margin-left
toc-margin-right
toc-margin-top
toc-margin-bottom
toc-margin-header
toc-margin-footer

Set the page margins for the ToC.

All values should be specified as LENGTH in millimetres.

If you are writing a DOUBLE-SIDED document, the margin values will be used for ODD pages; left and right margins will be mirrored for EVEN pages.

BLANK or omitted leaves the current margin unchanged i.e. the margins current at the end of the document.

0 (zero) will set the margin to zero.

$outdent

Set a negative indent for the last line of each ToC entry.

Values should be BLANK string or any valid CSS LENGTH.

This will cause the line to extend beyond the right margin; you can prevent this by setting PADDING-RIGHT equal to this value.

Default: 0

toc-odd-header-name
toc-even-header-name
toc-odd-footer-name
toc-even-footer-name

Selects a header or footer by name to use for the ToC. The header/footer must already have been defined using DefHeaderByName(), DefFooterByName(), DefHTMLHeaderByName(), or DefHTMLFooterByName().

If you are writing a SINGLE-SIDED document, the values for ODD will be used for all pages, and values for EVEN will be ignored.

BLANK or omitted leaves the header/footer unchanged. NB BLANK will not unset the header. Set $toc- $odd-header-value to -1 to turn the header off.

toc-odd-header-value
toc-even-header-value
toc-odd-footer-value
toc-even-footer-value

Specify whether to show a header or footer in the ToC. The header/footer must already have been defined using DefHeaderByName(), DefFooterByName(), DefHTMLHeaderByName(), or DefHTMLFooterByName().

If you are writing a SINGLE-SIDED document, the values for ODD will be used for all pages, and values for EVEN will be ignored.

BLANK or omitted or 0 leaves the header/footer state unchanged.

Values (case-insensitive)

1 or 'on'
Show the selected header/footer in the ToC.
-1 or 'off'
Hide the selected header/footer in the ToC.
$toc-preHTML

Specify the HTML code to appear before the ToC e.g. '<h1>Contents</h1>'. Note that in contrast with the HTML equivalent <tocpagebreak> the text does not need to use HTML-entities.

BLANK or omitted will enter no text

$toc-postHTML

Specify the HTML code to appear after the ToC e.g. '<p>Comments to go below the ToC</p>'. Note that in contrast with the HTML equivalent <tocpagebreak> the text does not need to use HTML-entities.

BLANK or omitted will enter no text.

$toc-bookmarkText

Specify the text as it will appear as a BOOKMARK for the ToC  e.g. 'Content list'.

BLANK or omitted will not create a BOOKMARK.

$name

Specify which ToC to include at this point, 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.

$toc-pageselector

Select a named CSS @page for the  ToC.

BLANK or omitted or leaves the CSS page unchanged.

See Using @page for more information

$toc-sheet-size
$sheet-size

Can be specified either as:

  • string for a pre-defined page size, see values below, e.g. 'A5'
  • or as an array of width and height in millimetres e.g. array(210,297).

Default: BLANK - makes no change to the current sheet-size

Values (case-insensitive)

  • 'A0' - 'A10', 'B0' - 'B10', 'C0' - 'C10'
  • '4A0', '2A0', 'RA0' - 'RA4', 'SRA0' - 'SRA4'
  • 'Letter, 'Legal', 'Executive', 'Folio'
  • 'Demy', 'Royal'
  • 'A' (Type A paperback 111x178mm)
  • 'B' (Type B paperback 128x198mm)

All of the above values can be suffixed with '-L' to force a Landscape page orientation document e.g. 'A4-L'

The rest of the parameters are defined exactly as for AddPageByArray(). Note that these parameters define page numbering, margins, headers/footers for the document as it continues from this point on; in the final document this will be the part of the document immediately after the ToC.

Please refer to AddPageByArray() for further details.

Changelog

Version Description
5.0 Function was added.
5.7

$outdent parameter added

and parameters $font, $font-size and $indent redundant/ignored

Examples

Example #1

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

$mpdf->WriteHTML('Introduction');
$mpdf->TOCpagebreakByArray();

$mpdf->TOC_Entry("Chapter 1",0);
$mpdf->WriteHTML('Chapter 1 ...');

$mpdf->Output();

Example #2 - Blank template as example

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

$mpdf->WriteHTML('Introduction');
$mpdf->TOCpagebreakByArray(array(
    'tocfont' => '',
    'tocfontsize' => '',
    'tocindent' => '',
    'TOCusePaging' => true,
    'TOCuseLinking' => '',
    'toc_orientation' => '',
    'toc_mgl' => '',
    'toc_mgr' => '',
    'toc_mgt' => '',
    'toc_mgb' => '',
    'toc_mgh' => '',
    'toc_mgf' => '',
    'toc_ohname' => '',
    'toc_ehname' => '',
    'toc_ofname' => '',
    'toc_efname' => '',
    'toc_ohvalue' => 0,
    'toc_ehvalue' => 0,
    'toc_ofvalue' => 0,
    'toc_efvalue' => 0,
    'toc_preHTML' => '',
    'toc_postHTML' => '',
    'toc_bookmarkText' => '',
    'resetpagenum' => '',
    'pagenumstyle' => '',
    'suppress' => '',
    'orientation' => '',
    'mgl' => '',
    'mgr' => '',
    'mgt' => '',
    'mgb' => '',
    'mgh' => '',
    'mgf' => '',
    'ohname' => '',
    'ehname' => '',
    'ofname' => '',
    'efname' => '',
    'ohvalue' => 0,
    'ehvalue' => 0,
    'ofvalue' => 0,
    'efvalue' => 0,
    'toc_id' => 0,
    'pagesel' => '',
    'toc_pagesel' => '',
    'sheetsize' => '',
    'toc_sheetsize' => '',
));

$mpdf->TOC_Entry("Chapter 1", 0);
$mpdf->WriteHTML('Chapter 1 ...');

$mpdf->Output();

See Also

Fork me on GitHub