Skip to main content
Version: 3

Example of Text and Image Watermarks in PDF Templates

Watermarks

The plugin ships with a number of PDF templates showing off the features of mPDF. These can be found in your PDF_EXTENDED_TEMPLATES directory.

Overview

To easily switch between custom PDF templates change the template URL query string parameter to the template name when viewing a PDF via your admin area.
The Watermark functions were added in Gravity PDF v3.4.0
Template Name: example-watermark09.php Example URL: https://test.com/?gf_pdf=1&fid=3&lid=40&template=example-watermark09.php

The watermark is a semi-transparent background printed on each page. Text and image watermarks can be applied using a custom HTML tag, and you have control over the watermark opacity.

Download Example PDF

Text Watermark

<watermarktext content [ alpha ] />
The watermark content attribute must have special characters properly encoded. This includes the <, >, ', " and & symbols. We recommend using htmlspecialcharsto prevent any problems.
Setting the content attribute blank will clear the watermark.
<!-- Setting watermark to Draft's with a 0.1 transparency -->
<watermarktext content="<?php echo htmlspecialchars("DRAFT'S", ENT_QUOTES); ?>" alpha="0.1" />

<!-- Setting watermark to Private with a 0.5 transparency -->
<watermarktext content="<?php echo htmlspecialchars("PRIVATE", ENT_QUOTES); ?>" alpha="0.5" />

<!-- Disabling watermark -->
<watermarktext content="" />

Image Watermark

<watermarkimage  src [ alpha ] [ size ] [ position ] />

The image watermark only requires the src attribute. The alpha, size and position attributes are all optional.

SRC The URL or PATH to the image. We recommend using the image path as it has better support across a range of hosting environments.

SIZE D Default size (original size of image) - depends on DPI settings PResize to fit the full page size, keeping aspect ratio F Resize to fit the print-area (frame) respecting current page margins, keeping aspect ratio INT Resize to full page size minus a margin set by this integer in millimetres, keeping aspect ratio 2 comma-separated numbers ($width, $height): Specify a size; units are in millimetres DEFAULT: "D"

POSITION P Centered on the whole page area F Centered on the page print-area (frame) respecting page margins 2 comma-separated numbers ($x, $y): Specify a position; units are in millimetres DEFAULT: "P"

<!-- Image watermark using the original size and centered on the page -->
<watermarkimage src"/path/to/images/gravitypdf.jpg" alpha="0.1" size="D" position="P" />

<!-- Image watermark resized to full page size and centered on the page print area -->
<watermarkimage src"/path/to/images/gravitypdf.jpg" alpha="0.5" size="P" position="F" />

<!-- Image watermark with default size positioned at 1mm from the top and 1mm from the left (X, Y) -->
<watermarkimage src"/path/to/images/gravitypdf.jpg" alpha="0.1" size="D" position="50,10" />

<!-- Image watermark with a 50x50mm image centered on the whole page -->
<watermarkimage src"/path/to/images/gravitypdf.jpg" alpha="0.5" size="50, 50" position="P" />

mPDF Documentation