Watermarking specific pages
Use the pages selector to stamp only a cover, an appendix, or every page but the first with a text or image watermark.
By default a watermark lands on every page. The pages field narrows that to a
precise subset — a cover page, an appendix, everything but the first page — so
you can stamp exactly where you need to. Both Add text
watermark and Add image
watermark accept it, and it works the same
way on every action that takes a pages field.
The pages selector
pages is a comma-separated list of 1-based page numbers and ranges. It is
treated as a set: order and duplicates are ignored, and pages are always
stamped in document order. Omitting it selects every page. See Selecting
pages for the complete syntax.
| Goal | pages value |
|---|---|
| The cover page only | 1 |
| Every page but the first | 2.. |
| Every page but the last | ..-2 |
| The last page only | -1 |
| An appendix from page 8 onward | 8.. |
| A specific set of pages | 1..3,5 |
| The last three pages | -3..-1 |
Stamp every page but the cover
A common request: a running confidentiality mark on the body of a document, but
not over the title page. Select pages=2.. — page 2 through the last page.
curl https://api.pdfblocks.com/v1/add_text_watermark \
-H 'X-API-Key: your_api_key' \
-F file=@input.pdf \
-F line_1='CONFIDENTIAL' \
-F pages='2..' \
-o watermarked.pdf# pip install requests
import requests
with open('input.pdf', 'rb') as file:
response = requests.post(
'https://api.pdfblocks.com/v1/add_text_watermark',
headers={'X-API-Key': 'your_api_key'},
files={'file': file},
data={'line_1': 'CONFIDENTIAL', 'pages': '2..'},
)
response.raise_for_status()
with open('watermarked.pdf', 'wb') as output:
output.write(response.content)// Node.js 18+
import { readFile, writeFile } from 'node:fs/promises';
const body = new FormData();
body.set('file', new Blob([await readFile('input.pdf')]), 'input.pdf');
body.set('line_1', 'CONFIDENTIAL');
body.set('pages', '2..');
const response = await fetch('https://api.pdfblocks.com/v1/add_text_watermark', {
method: 'POST',
headers: { 'X-API-Key': 'your_api_key' },
body,
});
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
await writeFile('watermarked.pdf', Buffer.from(await response.arrayBuffer()));<?php
$ch = curl_init('https://api.pdfblocks.com/v1/add_text_watermark');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['X-API-Key: your_api_key'],
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => [
'file' => new CURLFile('input.pdf', 'application/pdf'),
'line_1' => 'CONFIDENTIAL',
'pages' => '2..',
],
]);
$pdf = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200) {
file_put_contents('watermarked.pdf', $pdf);
}# gem install http
require 'http'
response = HTTP
.headers('X-API-Key' => 'your_api_key')
.post('https://api.pdfblocks.com/v1/add_text_watermark', form: {
file: HTTP::FormData::File.new('input.pdf'),
line_1: 'CONFIDENTIAL',
pages: '2..',
})
File.write('watermarked.pdf', response.body) if response.status.success?package main
import (
"bytes"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
var buf bytes.Buffer
form := multipart.NewWriter(&buf)
file, _ := os.Open("input.pdf")
defer file.Close()
part, _ := form.CreateFormFile("file", "input.pdf")
io.Copy(part, file)
form.WriteField("line_1", "CONFIDENTIAL")
form.WriteField("pages", "2..")
form.Close()
req, _ := http.NewRequest("POST",
"https://api.pdfblocks.com/v1/add_text_watermark", &buf)
req.Header.Set("Content-Type", form.FormDataContentType())
req.Header.Set("X-API-Key", "your_api_key")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
out, _ := os.Create("watermarked.pdf")
defer out.Close()
io.Copy(out, res.Body)
}using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-Key", "your_api_key");
using var form = new MultipartFormDataContent
{
{ new ByteArrayContent(File.ReadAllBytes("input.pdf")), "file", "input.pdf" },
{ new StringContent("CONFIDENTIAL"), "line_1" },
{ new StringContent("2.."), "pages" },
};
var response = await client.PostAsync(
"https://api.pdfblocks.com/v1/add_text_watermark", form);
response.EnsureSuccessStatusCode();
await File.WriteAllBytesAsync(
"watermarked.pdf", await response.Content.ReadAsByteArrayAsync());More targeting patterns
The only thing that changes between these is the pages value. Each snippet
writes to a different output file.
# pages=1 — stamp just the title page.
curl https://api.pdfblocks.com/v1/add_text_watermark \
-H 'X-API-Key: your_api_key' \
-F file=@input.pdf \
-F line_1='DRAFT' \
-F pages='1' \
-o cover.pdf# pages=..-2 — the first page through the second-to-last.
curl https://api.pdfblocks.com/v1/add_text_watermark \
-H 'X-API-Key: your_api_key' \
-F file=@input.pdf \
-F line_1='DO NOT DISTRIBUTE' \
-F pages='..-2' \
-o body.pdf# pages=8.. — page 8 to the end.
curl https://api.pdfblocks.com/v1/add_text_watermark \
-H 'X-API-Key: your_api_key' \
-F file=@input.pdf \
-F line_1='APPENDIX' \
-F pages='8..' \
-o appendix.pdf# pages=1..3,5 — pages 1, 2, 3, and 5.
curl https://api.pdfblocks.com/v1/add_text_watermark \
-H 'X-API-Key: your_api_key' \
-F file=@input.pdf \
-F line_1='REVIEW COPY' \
-F pages='1..3,5' \
-o review.pdfImage watermarks target the same way
An image watermark uses an identical pages field — pass a PNG or JPEG in the
image field alongside file. This stamps a logo on the cover page only:
curl https://api.pdfblocks.com/v1/add_image_watermark \
-H 'X-API-Key: your_api_key' \
-F file=@input.pdf \
-F image=@logo.png \
-F pages='1' \
-o watermarked.pdf# pip install requests
import requests
with open('input.pdf', 'rb') as file, open('logo.png', 'rb') as image:
response = requests.post(
'https://api.pdfblocks.com/v1/add_image_watermark',
headers={'X-API-Key': 'your_api_key'},
files={'file': file, 'image': image},
data={'pages': '1'},
)
response.raise_for_status()
with open('watermarked.pdf', 'wb') as output:
output.write(response.content)// Node.js 18+
import { readFile, writeFile } from 'node:fs/promises';
const body = new FormData();
body.set('file', new Blob([await readFile('input.pdf')]), 'input.pdf');
body.set('image', new Blob([await readFile('logo.png')]), 'logo.png');
body.set('pages', '1');
const response = await fetch('https://api.pdfblocks.com/v1/add_image_watermark', {
method: 'POST',
headers: { 'X-API-Key': 'your_api_key' },
body,
});
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
await writeFile('watermarked.pdf', Buffer.from(await response.arrayBuffer()));The same pages selector drives the page-oriented actions too — Extract
pages, Remove
pages, and Rotate
pages all read it the same way. Learn it once,
reuse it everywhere.