File & PDF Tools

Watermark PDF

Add a configurable text watermark to selected PDF pages.

Watermark PDF
Overlay a centered text watermark on selected pages.
Local browser processing

Watermark PDF

Render text with your browser font into a transparent PNG watermark and overlay it on selected pages, including non-Latin text.

Controls

  • Text, size, angle, and opacity
  • Page range
  • The watermark is written into a new PDF

Stamps a text watermark onto selected pages of a PDF by rasterising the wording with Canvas at twice the requested size, then placing the PNG as one rotated image XObject centred on each page. Use it for DRAFT and CONFIDENTIAL markings, ownership notices, and review copies that need non-Latin text a PDF font cannot supply.

The stamp is a raster PNG, not PDF text

pdf-lib writes page text with the standard 14 fonts in WinAnsi, a single-byte cp1252 map with no glyphs for Chinese or any non-Latin script. This tool sidesteps that ceiling by drawing the string on an offscreen canvas at two times the font size, calling toBlob("image/png"), and passing the result to embedPng. The artifact is an image XObject carrying /ColorSpace /DeviceRGB plus an /SMask generated from the PNG alpha channel, so the area around the letters stays transparent. Nothing is written as text, which means the wording never enters the text layer: Ctrl+F, copy-paste and pdftotext all miss it. Drawing at 2x and halving sets one canvas pixel to 0.5 pt, a fixed 144 ppi raster.

Centring a rotated image XObject

drawImage does accept rotate, but pdf-lib pivots on the image origin, its lower-left corner, not the page centre, so the obvious x = width/2 - w/2 slides off-centre as the angle grows. The code instead shifts the origin by the rotated half-extents: x = W/2 - (cos*w/2 - sin*h/2) and y = H/2 - (sin*w/2 + cos*h/2), which pins the stamp centre to its intended point for any angle between -180 and 180. Note that getSize() returns MediaBox dimensions: on a page whose CropBox is a smaller window, the label is centred in full-sheet coordinates and can land partly outside the visible area. Each page in the range receives its own transform, so a 40-page range repeats the same transform block 40 times.

Opacity, halo, and print contrast

Glyphs are filled with #111827 and stroked with a 90%-opaque white outline of max(2, 0.055 * font px): at Size 64 that is a 7.04 px stroke, 3.52 pt once halved, which is what keeps a pale stamp readable over photographs and tinted artwork. Fill and halo are flattened into the same PNG, so the opacity slider from 5% to 90% fades them together; you cannot keep a crisp white keyline while letting the letters vanish. Opacity is applied when the image is drawn rather than baked into pixels, so a 60-page document stores one PNG and repeats only a graphics-state reference plus a short transform per page.

Worked example

What Size 64 actually produces

Input
Any watermark text; Size 64; Angle 0; Opacity 0.32
Output
Canvas font 128 px, padding 58 px per side, white halo 7.04 px wide, canvas height 398 px. Drawn at half scale on the page: 64 pt glyphs, 3.52 pt outline, a 199 pt tall image at 0.5 pt per pixel.

Every value comes from the same two-step pipeline: render at 2x, then scale(0.5). The 128 px font lands as 64 pt glyphs, so the Size control behaves as points. Padding is ceil(64 * 2 * 0.45) = 58 px, which keeps a rotated stamp clear of its own edges, and the outline is max(2, 0.055 * 128) = 7.04 px, meaning small sizes hit a flat 2 px floor, 1 pt in the output.

Limits and pitfalls

  • Text is capped at 120 characters and the stamp is never fitted to the page: Size 160 already yields a 496 pt tall image, 59% of an A4 sheet, so long strings on narrow pages run past the CropBox edge.
  • Size accepts 8-160 and Opacity 5-90%, so a fully opaque or fully invisible stamp is impossible, and the glyph colour is fixed at #111827 with a white outline.
  • One centred instance per page: no tiling, no corner placement, no per-page text; pages outside the entered range are copied unchanged.
  • Encrypted or password-protected PDFs are rejected outright, and a single run accepts at most 250 MB of input.
  • Because the wording is an image, search, copy-paste and text extraction cannot see it, and the file is re-serialised on save, which invalidates existing digital signatures.

Related tools

When it goes wrong

I typed 1,1,1 into Pages to stack three stamps and the watermark came out exactly as light as before.

CauseThe page expression is parsed with unique left at its default of true, so repeats are collapsed before the drawing loop ever sees them; the loop then issues one drawImage per page index, and nothing draws a second copy over the first.

FixStop typing the page number twice and move the two real levers: Opacity runs up to 0.9 and Size up to 160, both applied to the single stamp per page.

At Size 10 the stamp is an unreadable grey smudge, while Size 64 looks clean.

CauseThe halo is stroked at max(2, size * 2 * 0.055) px on a canvas rendered at 2×: at Size 10 that formula gives 1.1 px, so the flat 2 px floor takes over — a stroke one tenth of the 20 px font height, which is 1 pt of white laid over 10 pt letters. Because the stroke is centred on the glyph path, half of it eats into the letterform and the letters close up.

FixKeep Size at 19 or above, where 0.055 * 2 * size finally clears the floor (19 → 2.09 px) and the outline scales with the type; get a discreet stamp from Opacity 0.05–0.2 rather than from tiny type.

The red error shows up the instant I drop the file, before I press Add watermark, saying password-protected PDFs are unsupported.

CauseThe file is loaded for its page count through PDFDocument.load without ignoreEncryption, so any document carrying an /Encrypt dictionary throws at selection time — including files that open without a password prompt because only the owner password was set.

FixStrip the restriction before stamping, for example qpdf --decrypt in.pdf open.pdf, then load the decrypted copy; the tool never touches the original.

I changed the wording, pressed Download, and got a file with the old watermark on it.

CauseOnly file selection, file-list edits and the run itself call the reset that clears the stored blob; the four watermark inputs have no watcher, so the previous result card and its blob stay alive and the Download button keeps serving them.

FixPress Add watermark again after every edit and download from the freshly rendered result card; the summary line above the button reports the page count of the file you are about to save.

The stamp sits at a sensible slope on most pages but looks about 90° wrong on the landscape scans.

CauseContent is drawn in the page's unrotated coordinate system, and the viewer applies /Rotate on top of it. Size comes from getSize() and only the Angle box is passed to drawImage, so on a page holding /Rotate 90 your −35° lands as 55° on screen.

FixCompensate per page type: on pages the viewer turns 90° clockwise enter Angle − 90 (−125 keeps the −35° look), or normalise the file with PDF page rotation first and stamp afterwards.

One concrete scenario

A 96-page bid that leaves three pages clean

A 96-page tender goes to three outside reviewers, so pages 4–96 carry a "仅供评审" stamp: typing 4-96 marks 93 pages and leaves the cover, signature page and price schedule untouched. At Size 110 the canvas is 682 px tall — a 220 px font plus 99 px padding a side — which lands as 341 pt, 40% of A4's 842 pt height. Four full-width glyphs measure about 440 pt at that size, so a −35° stamp spans 0.819×440 + 0.574×341 ≈ 556 pt across a 595 pt MediaBox, some 20 pt of slack a side. Size 160 drives the same four characters to ≈ 809 pt and off the sheet; when the mark looks faint on scans, raise Opacity, because one PNG serves every stamped page.

Frequently Asked Questions

Can a watermark be removed?
Yes — for anyone who understands PDF structure, a light watermark is cheap to strip. A text watermark asserts ownership and raises the abuse bar; it is not encryption. Real protection for valuable documents combines access control, traceable watermarking, and legal remedies.
What opacity and angle work best?
Start from 10–20% opacity at -45° (bottom-left to top-right). Too dark reads hostile and obscures text; too light vanishes in print. Contracts suit ~15% gray diagonal; marketing copies can go bolder.
Will Chinese watermarks render as boxes?
No. Watermarks render through your browser’s local fonts into a transparent layer, so Chinese and English appear exactly as typed — far friendlier than server-side fixed-font approaches.

Content reviewed: