mPDF Manual – mPDF classes

\Mpdf\WatermarkImage

(mPDF ≥ 8.2.0)

\Mpdf\WatermarkImage()

Description

\Mpdf\Watermark ( string $path [, int|array $size [, string|array $position [, float $alpha [, bool $behindContent [, string $alphaBlend ]]]]])

Parameters

$path

Path to the image of the watermark

$size

Defines the size of the watermark. This parameter takes either a pre-defined string, an integer, or an array of width and height.

Values

  • \Mpdf\Watermark::SIZE_DEFAULT
    default i.e. original size of image - may depend on img_dpi
  • \Mpdf\Watermark::SIZE_FIT_PAGE
    Resize to fit the full page size, keeping aspect ratio
  • \Mpdf\Watermark::SIZE_FIT_FRAME
    Resize to fit the print-area (frame) respecting current page margins, keeping aspect ratio
  • integer
    Resize to full page size minus a margin set by this integer in millimeters, keeping aspect ratio
  • array [$width, $height]
    Specify a size; units in millimeters

Default: \Mpdf\Watermark::SIZE_DEFAULT

$position

Defines the position of the watermark on the page. This parameter takes either a pre-defined string or an array of $x and $y.

Values

  • \Mpdf\Watermark::POSITION_CENTER_PAGE: Centred on the whole page area
  • \Mpdf\Watermark::POSITION_CENTER_FRAME: Centred on the page print-area (frame) respecting page margins
  • array [$width, $height]: Specify a position; units in millimeters

Default: \Mpdf\Watermark::POSITION_CENTER_PAGE

$alpha

Alpha of the watermark, values 0-1. 0 = fully visible, 1 = transparent.

$behindContent

Specify whether to place watermark images behind page contents

Values

  • true: place watermark images behind page contents
  • false: place watermark images in front of all page contents

Default: false

$alphaBlend

Specifies the blend mode for overlying watermark images. Different blend modes work with different types of images. The blend modes are those specified in the PDF reference. The value of 'Normal' gives acceptable results for most cases. 'Multiply' may produce better results with overlying WMF or SVG images.

Values

  • 'Normal'
  • 'Multiply'
  • 'Screen'
  • 'Overlay'
  • 'Darken'
  • 'Lighten'
  • 'ColorDodge'
  • 'ColorBurn'
  • 'HardLight'
  • 'SoftLight'
  • 'Difference'
  • 'Exclusion'

Default: 'Normal'

Examples

Example #1

<?php
$mpdf->SetWatermarkImage(new \Mpdf\WatermarkImage(
    'assets/tiger.wmf',
    \Mpdf\WatermarkImage::SIZE_DEFAULT,
    \Mpdf\WatermarkImage::POSITION_CENTER_PAGE,
    0.2,
    true
));

Fork me on GitHub