mPDF Manual – mPDF functions

SetWatermarkText()

(mPDF >= 2.2)

SetWatermarkText – Set the text to use as a Watermark

Description

void SetWatermarkText ( [ string $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 1 or TRUE

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. 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 and 1.

DEFAULT: 0.2

Changelog

VersionDescription
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. $mpdf->SetWatermarkText(); can be used as well as: $mpdf->SetWatermarkText('');

Examples

Example #1

<?php

$mpdf = new mPDF();

$mpdf->SetWatermarkText('DRAFT');

$mpdf->showWatermarkText = true;

$mpdf->WriteHTML('
Hallo World
');

?>

Example #2

<?php

// htmltoolkit contains a function strcode2utf() to convert htmlentities to UTF-8 encoded text$mpdf = new mPDF();

$wm = strcode2utf("&amp;#1575;&amp;#1610;&amp;#1604;&amp;#1575;&amp;#1578; &amp;#1601;&amp;#1610;&amp;#1605;&amp;#1575; &amp;#1575;&amp;#1610;&amp;#1604;&amp;#1575;&amp;#1578; &amp;#1601;&amp;#1610;&amp;#1605;&amp;#1575;");

$mpdf->SetWatermarkText($wm, 0.1);

$mpdf->showWatermarkText = true;

$mpdf->WriteHTML('
Hallo World
');

?>

See Also