Watermark PDF Guide

Develop your own solution to add image or text watermarks to PDF files by integrating with iLovePDF’s REST API.

New to the API? Start with Processing a PDF: every tool guide builds on its task flow.

Basic add a watermark

You can add a watermark to your PDF files as shown in this code:

Basic add watermarks
// Create a new task
$myTaskWatermark = $ilovepdf->newTask('watermark');
// Add files to task for upload
$file1 = $myTaskWatermark->addFile('path/to/file1_name.pdf');
// Select watermark parameters
$myTaskWatermark->setText('myWatermarkText');
// Execute the task
$myTaskWatermark->execute();
// Download the package files
$myTaskWatermark->download();
PHP library ilovepdf/ilovepdf-phpcomposer require ilovepdf/ilovepdf-php

The Watermark tool is composed of 2 different modes that can be configured through the property mode: text mode adds text watermarks and image mode adds image-based watermarks. The image mode is limited to PNG and JPG format files no bigger than 1Mb.


There is a list of default settings which can be customized, as you will see later:

  • The watermark will be stamped onto all pages
  • The transparency of the watermark is set by default at 100, which is zero transparency, full opacity
  • The watermark will be stamped over the PDF content
  • Its vertical position will be in the middle of the page and its horizontal position will be centered
  • The default font used for text will be Arial Unicode MS with a 14px size
  • The text color will be #000000, black

These settings and more can be customized as we explain in the next sections.

Advanced add watermarks

Pages for adding a watermark

Pages for adding a watermark
// Select watermark parameters
$myTaskWatermark->setText('iLovePDF');
$myTaskWatermark->setPages('1,6,9');
// Execute the task
$myTaskWatermark->execute();
PHP library ilovepdf/ilovepdf-phpcomposer require ilovepdf/ilovepdf-php

pages has plenty of options to set which pages have to be stamped by a watermark. See these parameters below:

  • all stamps all pages with the watermark. This is the default value.
  • 3-end stamps from the third page to the last page.
  • 1,3,4-9 stamps pages 1 and 3 and pages 4 to 9.
  • -2-end stamps the last 2 pages.
  • 3-234 stamps pages 3 to 234.

Setting watermark opacity

Setting watermark opacity
// Select watermark parameters
$myTaskWatermark->setText('iLovePDF');
$myTaskWatermark->setTransparency(50);
// Execute the task
$myTaskWatermark->execute();
PHP library ilovepdf/ilovepdf-phpcomposer require ilovepdf/ilovepdf-php

With transparency you can set the opacity intensity of a watermark for both text (as shown in the code example) and image watermarks, from 1 to 100 (100, the default, is fully opaque).

Setting watermark layer depth

Setting watermark layer depth
// Select watermark parameters
$myTaskWatermark->setText('iLovePDF');
$myTaskWatermark->setLayer('below');
// Execute the task
$myTaskWatermark->execute();
PHP library ilovepdf/ilovepdf-phpcomposer require ilovepdf/ilovepdf-php

layer places your watermark below or above the PDF content. It is set to above by default.

Vertical position of watermark

Vertical position of watermark
// Select watermark parameters
$myTaskWatermark->setText('iLovePDF');
$myTaskWatermark->setVerticalPosition('bottom');
// Execute the task
$myTaskWatermark->execute();
PHP library ilovepdf/ilovepdf-phpcomposer require ilovepdf/ilovepdf-php

vertical_position lets you set the vertical position of your watermark at the following places:

  • bottom places the watermark at the bottom end of the page with a default margin.
  • top places the watermark at the top end of the page with a default margin.
  • middle places the watermark at the middle of the page.

Horizontal position of watermark

Horizontal position of watermark
// Select watermark parameters
$myTaskWatermark->setText('iLovePDF');
$myTaskWatermark->setHorizontalPosition('left');
// Execute the task
$myTaskWatermark->execute();
PHP library ilovepdf/ilovepdf-phpcomposer require ilovepdf/ilovepdf-php

horizontal_position lets you set the horizontal position of your watermark at the following places:

  • left places the watermark on the left side of the page with a default margin.
  • right places the watermark on the right side of the page with a default margin.
  • center places the watermark in the center of the page.

Watermark mosaic

Watermark mosaic
// Select watermark parameters
$myTaskWatermark->setText('iLovePDF');
$myTaskWatermark->setMosaic(true);
// Execute the task
$myTaskWatermark->execute();
PHP library ilovepdf/ilovepdf-phpcomposer require ilovepdf/ilovepdf-php

If mosaic is set to true, your watermark will be stamped 9 times per page in a 3x3 mosaic, overriding all position parameters.

Watermark rotation

Watermark rotation
// Select watermark parameters
$myTaskWatermark->setText('iLovePDF');
$myTaskWatermark->setRotation(30);
// Execute the task
$myTaskWatermark->execute();
PHP library ilovepdf/ilovepdf-phpcomposer require ilovepdf/ilovepdf-php

rotation will stamp your watermark rotated by the specified number of degrees (from 0 to 360).

Set a watermark font format

Note that this function only works with text-based watermarks. Font settings are ignored for image watermarks.

Set a watermark font format
// Select watermark parameters
$myTaskWatermark->setText('iLovePDF');
$myTaskWatermark->setFontFamily('Courier');
$myTaskWatermark->setFontSize(18);
$myTaskWatermark->setFontColor('#ffffff');
// Execute the task
$myTaskWatermark->execute();
PHP library ilovepdf/ilovepdf-phpcomposer require ilovepdf/ilovepdf-php

font_family, font_style, font_size and font_color are properties to customize text font format. The font_family property changes which font will be used, the font_style property changes the text style such as bold or italic, the font_size property changes the font size, and the font_color property changes the color of the watermark text.