SetWatermarkText()
(mPDF ≥ 2.2)
SetWatermarkText – Set the text to use as a Watermark
Description
void SetWatermarkText ( [ string|\Mpdf\WatermarkText $text [, float $alpha ]] )
Set the text to use as a Watermark. The watermark is a semi-transparent background printed on each page, used for text such as “DRAFT”. The watermark will be added to each page when the Footer is printed if the variable $showWatermark is set to a truthy value.
Parameters
- $text
-
This parameter defines the text to use for the watermark. The text should be UTF-8 encoded, but should not contain HTML mark-up tags.
Since 8.2.0 the value can be an instance of \Mpdf\WatermarkText class. Its properties then overwrite internal watermark variables.
If the text is blank, it will clear the watermark text, so nothing appears.
Default: BLANK
- $alpha
-
This parameter defines the transparency value (alpha) to use for the watermark: either text or image. The Value should be between
0
and1
.Default:
0.2
Changelog
Version | Description |
---|---|
2.2 | The function was added. |
2.2 | Parameter $alpha was added |
3.0 | Parameter $text changed to be optional |
3.0 |
No parameters are required from v3.0 onwards
e.g. |
8.2.0 | \Mpdf\WatermarkText object was introduced. |
Examples
Example #1 (Since mPDF 8.2.0)
<?php
$mpdf = new \Mpdf\Mpdf();
$mpdf->SetWatermarkText(new \Mpdf\WatermarkText('DRAFT'));
$mpdf->showWatermarkText = true;
Example #2
<?php
$mpdf = new \Mpdf\Mpdf();
$mpdf->SetWatermarkText('DRAFT');
$mpdf->showWatermarkText = true;
$mpdf->WriteHTML('Hello World');
Example #3
<?php
$mpdf = new \Mpdf\Mpdf();
// The library defines a function strcode2utf() to convert htmlentities to UTF-8 encoded text
$wm = strcode2utf("&#1575;&#1610;&#1604;&#1575;&#1578; &#1601;&#1610;&#1605;&#1575; &#1575;&#1610;&#1604;&#1575;&#1578; &#1601;&#1610;&#1605;&#1575;");
$mpdf->SetWatermarkText($wm, 0.1);
$mpdf->showWatermarkText = true;
$mpdf->WriteHTML('Hello World');
See Also
- \Mpdf\WatermarkText() - Watermark text data transfer object
- <watermarktext> - HTML equivalent of SetWatermarkText()
- SetWatermarkImage() - Set an image to use as a Watermark
- $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