mPDF Manual – What Else Can I Do

Watermarks

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.

Version >=8.2.0

<?php
$mpdf->SetWatermarkText(new \Mpdf\WatermarkText('DRAFT')); // Will cope with UTF-8 encoded text

Version <=8.1.6

<?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: 0.2) using

<?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.

Set the watermark(s) to show using: showWatermarkText or showWatermarkImage

Changelog

Version Description
8.2.0 Watermark objects were introduced.

See

Fork me on GitHub