You can add a watermark to the page(s) either text (e.g. “DRAFT”) and/or a background image.
Set the following before writing the HTML code. NB The watermark is added when writing the footer at the end of a page, so it can be set anytime before ending the page/document.
Since version 8.2.0, watermark data objects were introduced. See below for previous style of setting watermarks which is still supported, but will be deprecated in the next major version.
<?php $mpdf->SetWatermarkText(new \Mpdf\WatermarkText('DRAFT')); // Will cope with UTF-8 encoded text
<?php $mpdf->SetWatermarkText('DRAFT'); // Will cope with UTF-8 encoded text $mpdf->watermark_font = 'DejaVuSansCondensed'; // Uses default font if left blank
You can alter the transparency values (Default:
<?php $mpdf->watermarkTextAlpha = 0.1; $mpdf->watermarkImageAlpha = 0.5;
A watermark image is set by default to print on top of the page contents. The opacity setting will alter the appearance of the text behind the image. You can optionally set the watermark to appear behind the page contents using watermarkImgBehind configuration setting, but note that the image will be hidden by any background colour specified, including table cells and the page background.
Note: In version 4.4 $watermarkImgBehind was unintentionally set
true in the config.php file.
Note: From mPDF ≥ 3.0 you can alternatively use the CSS
background-image on the
<body> tag to create a sort of watermark, although this does not support
opacity. The difference is that text, tables etc are written over the top of a background-image; a watermark is
actually printed over the top of everything else, but is semi-transparent.
|8.2.0||Watermark objects were introduced.|
- \Mpdf\WatermarkText() - Watermark text data transfer object
- \Mpdf\WatermarkImage() - Watermark image data transfer object
- SetWatermarkText() - Set the text to use as a Watermark
- <watermarktext> - HTML equivalent to
- SetWatermarkImage() - Set the image to use as a Watermark
- <watermarkimage> - HTML equivalent to
- watermarkImageAlpha - Specifies the transparency (alpha value) for the watermark image
- watermarkTextAlpha - Specifies the transparency (alpha value) for the watermark text
- showWatermarkText - Specifies whether or not to show/print the watermark text
- showWatermarkImage - Specifies whether or not to show/print the watermark image
- watermark_font - Specifies the font to use for Watermark text
- watermarkImgBehind - Specify whether to show the watermark image behind the page contents