(mPDF >= 2.2)
annotation – Add an Annotation to the document
<annotation $content [ $pos-x ] [ $pos-y ] [ $icon ] [ $author ] [ $subject ] [ $opacity ] [ $color ] [ $popup ] [ $file ] />
Adds an Annotation to the document. An annotation is like a Tooltip on a webpage. The Annotation marker, like those of “Sticky Notes” in Adobe Reader. When the reader passes the cursor over, it will display a popup text box.
The exact position on the page can be specified using $x and $y, or left to position automatically. If $x and $y are not specified, the Annotation will be inserted at the current position of writing in the document. The $x position (horizontal) can be overridden by the variable annotMargin, which can be used to force the Annotation marker to display in the right margin.
The attribute $file can be used to specify a file (any type) which is to be embedded inside the PDF document.
Note: All text to do with an annotation (text, author, subject) is rendered with the system font and can therefore contain any Unicode character even if the document font restricts to a specific codepage.
Note: To embed files, the
allowAnnotationFiles config key has to be set to
Warning: Embedding files is disabled by default, when enabling it, always ensure the path of the file is restricted to harmless files, otherwise the PDF could leak your system files.
Annotations cannot be moved or deleted by the reader.
This parameter specifies the text to appear in the popup text box.
$content cannot contain any of the characters:
"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.
Sets the $x position of the (bottom left edge of the) Annotation marker, set in mm from the left of the page.
BLANK or omitted or
0uses the current writing position on the page, unless overridden by $annotMargin.
Sets the $y position of the (bottom left edge of the) Annotation marker, set in mm from the top of the page. When Annotation markers are used within the text (annotMargin =
false), the marker is raised by the current lineheight to appear above the text.
BLANK or omitted or
0uses the current writing position on the page.
Sets the appearance of the Annotation marker.
BLANK or omitted uses Default: i.e.
Values (case sensitive)
Note: The default is
"Comment"when using Annotations from HTML markup
<span title="">when title2annots is
This specifies the name of the Author which will appear at the top of the popup text box.
This specifies the text to appear in the Annotation properties.
Sets the opacity of the Annotation marker. Values must be greater than
Specify the colour of the Annotation marker background.
Any valid CSS color recognised by mPDF:
- named colours such as
Specify whether to show the popup box for the annotation when the PDF document is opened, and optional specify its dimensions and/or position.
BLANK or omitted or
0- the popup box is not shown.
Any other value forces the popup box to appear when the document is opened.
<nn nn>- A string of 2 numbers (separated by spaces) will set the X and Y position in mm e.g.
'30 30'will show a popup box with the top left corner 30mm from the top of the page and 30mm from the left of the page.
<nn nn nn nn>- A string of 4 numbers (separated by spaces) will set the X and Y position and also the width and height in mm e.g.
'30 30 80 50'will show a popup box with the top left corner 30mm from the top of the page and 30mm from the left of the page, a width of 80mm and a height of 50mm.
Note that the PDF Reader (e.g. Adobe Reader) may reposition the popup box as it pleases.
Path to the file to embed in the PDF document.
|2.2||The function was added.|
Annotations cannot be moved or deleted.
|4.3||Attribute $popup was added|
|5.1||Attribute $file was added|
Attribute $file is ignored unless mPDF
<?php $mpdf = new \Mpdf\Mpdf(); $html = 'This is a paragraph about violas<annotation content="Violas are like big violins" /> about which I know very little.'; $mpdf->WriteHTML($html); $mpdf->Output();
<?php $mpdf = new \Mpdf\Mpdf(); // The Annotation markers will appear 10mm in from the right margin of the page $mpdf->annotMargin = 10; // The Annotation markers need no transparency as they appear in the margins $mpdf->annotOpacity = 1; $html = 'This is a paragraph about violas<annotation content="Violas are like big violins" /> about which I know very little.'; $mpdf->Output();