mPDF Manual – mPDF functions

TOCpagebreak()

(mPDF >= 2.0)

TOCpagebreak — Insert a table of contents in the document

Description

void TOCpagebreak ([ string $font [, float $font-size [, int $indent [, mixed $paging [, mixed $links [, string $toc-orientation [, float $toc-margin-left [, float $toc-margin-right [, float $toc-margin-top [, float $toc-margin-bottom [, float $toc-margin-header [, float $toc-margin-footer [, string $toc-odd-header-name [, string $toc-even-header-name [, string $toc-odd-footer-name [, string $toc-even-footer-name [, int $toc-odd-header-value [, int $toc-even-header-value [, int $toc-odd-footer-value [, int $toc-even-footer-value [, string $toc-preHTML [, string $toc-postHTML [, string $toc-bookmarkText [, string $resetpagenum [, string $pagenumstyle [, string $suppress [, string $orientation [, float $margin-left [, float $margin-right [, float $$margin-top [, float $$margin-bottom [, float $$margin-header [, float $margin-footer [, string $odd-header-name [, string $even-header-name [, string $$odd-footer-name [, string $$even-footer-name [, mixed $$odd-header-value [, mixed $even-header-value [, mixed $odd-footer-value [, mixed $$even-footer-value [, string $name [, string $pageselector [, string $toc-pageselector [, string $sheet-size [, string $toc-sheet-size [, string $outdent [, int $$toc-resetpagenum [, string $$toc-pagenumstyle [, mixed $$toc-suppress ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]])

Add a new page to the document, 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.

$font

From mPDF >= 5.7 CSS styles are used to control layout of ToCs. Any value set for this is ignored.

Set the font-family for the ToC.

BLANK or omitted uses default font-family for the document.

$font-size

From mPDF >= 5.7 CSS styles are used to control layout of ToCs. Any value set for this is ignored.

Sets the font size for the ToC in points (pt)

BLANK or omitted or 0 uses the default font-size for the document.

$indent

From mPDF >= 5.7 CSS styles are used to control layout of ToCs. Any value set for this is ignored.

Sets the value in millimetres to indent each level of the ToC from the left margin.

BLANK or omitted uses a default value of 5mm.

$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

</span>$toc-margin-top

toc-margin-bottom

</span>$toc-margin-header

toc-margin-footer</span>

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.

$toc-odd-header-name

toc-even-header-name</span>$

toc-odd-footer-name

</span>$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</span>$

toc-even-footer-value</span>

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 a pre-defined page size, 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”

$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-resetpagenum = 1 - ∞

Sets/resets the document page number to $resetpagenum starting on the ToC. (The value must be a positive integer).

BLANK or omitted or 0 leaves the preceding page number sequence unchanged.

$toc-pagenumstyle = 1 A a I i [+ any value supported for list-style-type]

Sets/resets the page numbering style to use in the ToC (values as for cf. lists)

BLANK or omitted leaves the current page number style unchanged.

Values (case-sensitive)

1: Decimal - 1,2,3,4…

A: Alpha uppercase - A,B,C,D…

a: Alpha lowercase - a,b,c,d…

I: Roman uppercase - I, II, III, IV…

i: Roman lowercase - i, ii, iii, iv…

$toc-suppress = TRUE FALSE 1 0

$suppress=on will suppress document page numbers in the ToC

BLANK or omitted leaves the current condition unchanged.

Values (case-insensitive)

1 or TRUE: Suppress (hide) page numbers in the ToC

0 or FALSE: Show page numbers in the ToC

The rest of the parameters are defined exactly as for AddPage(). 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 AddPage() for further details. But note there are differences in the order of the parameters especially take care with $orientation

Changelog

VersionDescription
2.0 Function was added.
2.2 Default values for $font-size, $paging and $links were redefined.
2.3 $name attribute was added.
4.3 Parameters $pageselector, $sheet-size, $toc-pageselector and $toc-sheet-size were added
5.7 $outdent parameter added $font, $font-size and $indent redundant
6.0 Parameters added:  $toc-resetpagenum | $toc-pagenumstyle | $toc-suppress

Examples

Example #1

<?php

$mpdf = new mPDF();

$mpdf->WriteHTML('Introduction');

$mpdf->TOCpagebreak();

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

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

$mpdf=Output();

?>

See Also