Version: 3
🔥 Gravity PDF v3 end of life was 2017-06-20 and this version is no longer supported. This legacy documentation is kept for reference only.
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
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 PDFText Watermark
<watermarktext content [ alpha ] />
The watermark
content
attribute must have special characters properly encoded. This includes the <
, >
, '
, "
and &
symbols. We recommend using htmlspecialchars
to prevent any problems.<!-- 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.
D
Default size (original size of image) - depends on DPI settingsP
Resize to fit the full page size, keeping aspect ratioF
Resize to fit the print-area (frame) respecting current page margins, keeping aspect ratioINT
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
"POSITIONP
Centered on the whole page areaF
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" />