mPDF Manual – HTML control tags

bookmark

(mPDF >= 1.0)

bookmark – Add a Bookmark to the document

Description

<bookmark  $content [ $level ] />

Add a Bookmark to the document. Bookmarks appear in Adobe Reader and link to specific points in the text. The target is set as the current writing position in the document when the Bookmark is defined.

Attributes

$content

Specifies the text to appear as a Bookmark.

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

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

$level

$level specifies the “tree” level for the Bookmark. The top level is 0. See Example #2 below. Accepts an integer from 0 to the maximum depth you wish.

Default: 0

Examples

Example #1

<html>

<bookmark content="Start of the Document" />

<div>Section 1 text</div>

</html>

Example #2

<html>

    <bookmark content="Section 1" />
    <div>Section 1 text</div>
    
    <bookmark content="Chapter 1" />
    <div>Chapter 1 text</div>
    
    <bookmark content="Chapter 2" />
    <div>Chapter 2 text</div>
    
    <bookmark content="Section 2" />
    <div>Section 2 text</div>
    
    <bookmark content="Chapter 3" />
    <div>Chapter 3 text</div>

</html>

This will produce a Bookmark tree in Adobe Reader:

+ Section 1
  + Chapter 1
  + Chapter 2
+ Section 2
  + Chapter 3

Notes

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


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

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


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

or just after a word to be marked:


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

Automatically Generated Bookmarks

You can automatically generate bookmarks from h1 - h6 tags, by setting the variable $h2bookmarks.

Define arrays with e.g. the tag => Bookmark level

Remember bookmark levels start at 0.

The tags H1 - H6 must be written with uppercase when defining the array.

Example:

<?php

$mpdf->h2bookmarks = array('H1'=>0, 'H2'=>1, 'H3'=>2);

See Also

Fork me on GitHub