- Get started
- Overview
- Getting started
- Processing a PDF
- Common functions
- Error handling
- Organize
-
Merge PDF
-
Split PDF
-
Smart Split PDF (AI)
-
Rotate PDF
-
Add page numbers
- Optimize
-
Compress PDF
-
Repair PDF
-
PDF to PDF/A
-
Validate PDF/A
- Convert
-
Office to PDF
-
HTML to PDF
-
Images to PDF
-
PDF to JPG
- Edit and secure
-
Edit PDF
-
Watermark PDF
-
Protect PDF
-
Unlock PDF
- AI and data
-
OCR PDF
-
Extract text
-
PDF to Markdown (AI)
-
AI Summarizer (AI)
-
Detect forms (AI)
- No matches.
Resources
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:
// 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();// Create a new task
var taskWatermark = api.CreateTask<WaterMarkTask>();
// Add files to task for upload
var file = taskWatermark.AddFile("path/to/file/file1_name.pdf");
// Select watermark parameters
var parameters = new WaterMarkParams(
new WatermarkModeText("myWatermarkText"));
// Execute the task
taskWatermark.Process(parameters);
// Download the package files
taskWatermark.DownloadFile();# Create a new task
my_task_watermark = ilovepdf.new_task :watermark
# Add files to task for upload
file1 = my_task_watermark.add_file 'path/to/file1_name.pdf'
# Select watermark parameters
my_task_watermark.text = 'myWatermarkText'
# Execute the task
my_task_watermark.execute
# Download the package files
my_task_watermark.downloadconst task = ilovepdf.newTask('watermark') as WatermarkTask;
task.start()
.then(() => {
return task.addFile(new ILovePDFFile('path/to/file1_name.pdf'));
})
.then(() => {
return task.process({ text: 'myWatermarkText' });
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejsThe 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
// Select watermark parameters
$myTaskWatermark->setText('iLovePDF');
$myTaskWatermark->setPages('1,6,9');
// Execute the task
$myTaskWatermark->execute();// Select watermark parameters
var parameters = new WaterMarkParams(
new WatermarkModeText("iLovePDF"))
{
Pages = "1,6,9"
};
// Execute the task
taskWatermark.Process(parameters);# Select watermark parameters
my_task_watermark.text = 'iLovePDF'
my_task_watermark.pages = '1,6,9'
# Execute the task
my_task_watermark.executeconst task = ilovepdf.newTask('watermark') as WatermarkTask;
task.start()
.then(() => {
return task.addFile(new ILovePDFFile('path/to/file1_name.pdf'));
})
.then(() => {
return task.process({ text: 'myWatermarkText', pages: '1,6,9' });
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejspages 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
// Select watermark parameters
$myTaskWatermark->setText('iLovePDF');
$myTaskWatermark->setTransparency(50);
// Execute the task
$myTaskWatermark->execute();// Select watermark parameters
var parameters = new WaterMarkParams(
new WatermarkModeText("iLovePDF"))
{
Transparency = 50
};
// Execute the task
taskWatermark.Process(parameters);# Select watermark parameters
my_task_watermark.text = 'iLovePDF'
my_task_watermark.transparency = 50
# Execute the task
my_task_watermark.executeconst task = ilovepdf.newTask('watermark') as WatermarkTask;
task.start()
.then(() => {
return task.addFile(new ILovePDFFile('path/to/file1_name.pdf'));
})
.then(() => {
return task.process({ text: 'myWatermarkText', transparency: 50 });
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejsWith 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
// Select watermark parameters
$myTaskWatermark->setText('iLovePDF');
$myTaskWatermark->setLayer('below');
// Execute the task
$myTaskWatermark->execute();// Select watermark parameters
var parameters = new WaterMarkParams(
new WatermarkModeText("iLovePDF"))
{
Layer = Layer.Below
};
// Execute the task
taskWatermark.Process(parameters);# Select watermark parameters
my_task_watermark.text = 'iLovePDF'
my_task_watermark.layer = 'below'
# Execute the task
my_task_watermark.executeconst task = ilovepdf.newTask('watermark') as WatermarkTask;
task.start()
.then(() => {
return task.addFile(new ILovePDFFile('path/to/file1_name.pdf'));
})
.then(() => {
return task.process({ text: 'myWatermarkText', layer: 'below' });
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejslayer places your watermark below or above the PDF content. It is set to above by default.
Vertical position of watermark
// Select watermark parameters
$myTaskWatermark->setText('iLovePDF');
$myTaskWatermark->setVerticalPosition('bottom');
// Execute the task
$myTaskWatermark->execute();// Select watermark parameters
var parameters = new WaterMarkParams(
new WatermarkModeText("iLovePDF"))
{
VerticalPosition = WaterMarkVerticalPositions.Bottom
};
// Execute the task
taskWatermark.Process(parameters);# Select watermark parameters
my_task_watermark.text = 'iLovePDF'
my_task_watermark.vertical_position = 'bottom'
# Execute the task
my_task_watermark.executeconst task = ilovepdf.newTask('watermark') as WatermarkTask;
task.start()
.then(() => {
return task.addFile(new ILovePDFFile('path/to/file1_name.pdf'));
})
.then(() => {
return task.process({ text: 'myWatermarkText', vertical_position: 'bottom' });
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejsvertical_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
// Select watermark parameters
$myTaskWatermark->setText('iLovePDF');
$myTaskWatermark->setHorizontalPosition('left');
// Execute the task
$myTaskWatermark->execute();// Select watermark parameters
var parameters = new WaterMarkParams(
new WatermarkModeText("iLovePDF"))
{
HorizontalPosition = WaterMarkHorizontalPositions.Left
};
// Execute the task
taskWatermark.Process(parameters);# Select watermark parameters
my_task_watermark.text = 'iLovePDF'
my_task_watermark.horizontal_position = 'left'
# Execute the task
my_task_watermark.executeconst task = ilovepdf.newTask('watermark') as WatermarkTask;
task.start()
.then(() => {
return task.addFile(new ILovePDFFile('path/to/file1_name.pdf'));
})
.then(() => {
return task.process({ text: 'myWatermarkText', horizontal_position: 'left' });
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejshorizontal_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
// Select watermark parameters
$myTaskWatermark->setText('iLovePDF');
$myTaskWatermark->setMosaic(true);
// Execute the task
$myTaskWatermark->execute();// Select watermark parameters
var parameters = new WaterMarkParams(
new WatermarkModeText("iLovePDF"))
{
Mosaic = true
};
// Execute the task
taskWatermark.Process(parameters);# Select watermark parameters
my_task_watermark.text = 'iLovePDF'
my_task_watermark.mosaic = true
# Execute the task
my_task_watermark.executeconst task = ilovepdf.newTask('watermark') as WatermarkTask;
task.start()
.then(() => {
return task.addFile(new ILovePDFFile('path/to/file1_name.pdf'));
})
.then(() => {
return task.process({ text: 'myWatermarkText', mosaic: true });
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejsIf mosaic is set to true, your watermark will be stamped 9 times per page in a 3x3 mosaic, overriding all position parameters.
Watermark rotation
// Select watermark parameters
$myTaskWatermark->setText('iLovePDF');
$myTaskWatermark->setRotation(30);
// Execute the task
$myTaskWatermark->execute();// Select watermark parameters
var parameters = new WaterMarkParams(
new WatermarkModeText("iLovePDF"))
{
Rotation = 30
};
// Execute the task
taskWatermark.Process(parameters);# Select watermark parameters
my_task_watermark.text = 'iLovePDF'
my_task_watermark.rotate = 30
# Execute the task
my_task_watermark.executeconst task = ilovepdf.newTask('watermark') as WatermarkTask;
task.start()
.then(() => {
return task.addFile(new ILovePDFFile('path/to/file1_name.pdf'));
})
.then(() => {
return task.process({ text: 'myWatermarkText', rotation: 30 });
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejsrotation 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.
// Select watermark parameters
$myTaskWatermark->setText('iLovePDF');
$myTaskWatermark->setFontFamily('Courier');
$myTaskWatermark->setFontSize(18);
$myTaskWatermark->setFontColor('#ffffff');
// Execute the task
$myTaskWatermark->execute();// Select watermark parameters
var parameters = new WaterMarkParams(
new WatermarkModeText("iLovePDF"))
{
FontFamily = "Arial",
FontSize = 12,
FontColor = "#ff0000",
};
// Execute the task
taskWatermark.Process(parameters);# Select watermark parameters
my_task_watermark.text = 'iLovePDF'
my_task_watermark.font_family = 'Courier'
my_task_watermark.font_size = 18
my_task_watermark.font_color = '#ffffff'
# Execute the task
my_task_watermark.executeconst task = ilovepdf.newTask('watermark') as WatermarkTask;
task.start()
.then(() => {
return task.addFile(new ILovePDFFile('path/to/file1_name.pdf'));
})
.then(() => {
return task.process({
text: 'myWatermarkText',
font_family: 'Verdana',
font_style: 'Bold',
font_size: 20,
font_color: '#FFFFFF',
});
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejsfont_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.