Bookmark()
(mPDF ≥ 1.0)
Bookmark – Add a Bookmark to the document
Description
void Bookmark ( string $content [, int $level [, float $y ]])
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.
Note: Bookmarks use Adobe Reader system fonts, therefore any Unicode text can be used, even if a unibyte codepage is being used for the document.
Parameters
- $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.<annotation content="This is < 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
- $y
-
$y specifies the y-coordinate on the page for the Bookmark. The top of the page is 0. The default is the current writing position on the page.
Examples
Example #1
<?php
$mpdf = new \Mpdf\Mpdf();
$mpdf->Bookmark('Start of the document');
$mpdf->WriteHTML('<div>Section 1 text</div>');
$mpdf->Output('filename.pdf');
Example #2
<?php
$mpdf = new \Mpdf\Mpdf();
$mpdf->Bookmark('Section 1', 0);
$mpdf->WriteHTML('<div>Section 1 text</div>');
$mpdf->Bookmark('Chapter 1', 1);
$mpdf->WriteHTML('<div>Chapter 1 text</div>');
$mpdf->Bookmark('Chapter 2', 1);
$mpdf->WriteHTML('<div>Chapter 2 text</div>');
$mpdf->Bookmark('Section 2', 0);
$mpdf->WriteHTML('<div>Section 2 text</div>');
$mpdf->Bookmark('Chapter 3', 1);
$mpdf->WriteHTML('<div>Chapter 3 text</div>');
$mpdf->Output('filename.pdf');
/*
This will produce a Bookmark tree in Adobe Reader:
+ Section 1
+ Chapter 1
+ Chapter 2
+ Section 2
+ Chapter 3
*/
Notes
Note: To set the Bookmark for a Table of Contents, see $toc-bookmarkText in TOCpagebreak().
See Also
- <bookmark> - Custom HTML tag - equivalent to
Bookmark()