Skip to content

Watermark

huzpsb edited this page Oct 25, 2026 · 1 revision

Watermark

Apply text, image or PDF watermarks underneath page content — the first thing rendered on every page. Visibility depends on the transparency of the layers above. For overlays on top see Stamp.

Command line

pdfcpu2 watermark add|update|remove [string|file] [description] inFile outFile --mode text|image|pdf

Three watermark kinds

# 1) Text
pdfcpu2 watermark add "DRAFT" "diag:1, scale:.8 rel, op:.25" in.pdf out.pdf --mode text
pdfcpu2 watermark add --mode text -- 'Page %p of %P' 'scale:1.0 abs, pos:bc, rot:0' in.pdf out.pdf

# 2) Image
pdfcpu2 watermark add logo.png '' in.pdf out.pdf --mode image

# 3) PDF
pdfcpu2 watermark add 'watermark.pdf:3' '' in.pdf out.pdf --mode pdf     # one page onto all
pdfcpu2 watermark add 'watermark.pdf' '' in.pdf out.pdf --mode pdf       # multiwatermark
pdfcpu2 watermark add 'watermark.pdf:2:3' '' in.pdf out.pdf --mode pdf   # start src:2 at dest:3

Description string

Same grammar as Stamp: font:, points:, pos:, off:, scale:, rot:/d:1|2 (diagonal), op: opacity, aligntext:, fillcolor:, strokecolor:, bgcol:, margins:, border:, rtl:, script: (CJK without font embedding: Hans, Hant, Hira, Kana, Jpan, Hang, Kore).

update / remove

pdfcpu2 watermark update "REVIEW" "diag:1, scale:.8 rel, op:.25" in.pdf out.pdf --mode text
pdfcpu2 watermark remove in.pdf out.pdf

Go API

package main

import (
	"context"

	"github.com/huzpsb/pdfcpu2/pkg/api"
	"github.com/huzpsb/pdfcpu2/pkg/pdfcpu/model"
)

func main() {
	ctx := context.Background()
	conf := model.NewDefaultConfiguration()

	// Text watermark; onTop=false = underneath content
	err := api.AddTextWatermarksFile(ctx, "in.pdf", "out.pdf", nil,
		false, "DRAFT", "diag:1, scale:.8 rel, op:.25", conf)
	if err != nil {
		panic(err)
	}

	// Image watermark
	err = api.AddImageWatermarksFile(ctx, "in.pdf", "out2.pdf", nil, false, "logo.png", "op:.3", conf)
	_ = err
}

Per-page watermarks: api.AddWatermarksMapFile(ctx, inFile, outFile, map[int]*model.Watermark, conf).

Clone this wiki locally