Skip to content
huzpsb edited this page Oct 25, 2026 · 1 revision

Stamp

Stamp text, images or PDF pages on top of selected pages — headers, footers, page numbers, approval marks, signatures, "CONFIDENTIAL" overlays. For content underneath everything else see Watermark.

Command line

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

Three stamp kinds

# 1) Text
pdfcpu2 stamp add "CONFIDENTIAL" "pos:tr, scale:.35 abs, op:.6" in.pdf out.pdf --mode text
pdfcpu2 stamp add --mode text -- 'Page %p of %P' 'scale:1.0 abs, pos:bc, rot:0' in.pdf out.pdf
#    %p = current page number (%p3 starts numbering at 3), %P = total pages

# 2) Image (.jpg .jpeg .png .tif .tiff .webp)
pdfcpu2 stamp add logo.png '' in.pdf out.pdf --mode image

# 3) PDF
pdfcpu2 stamp add 'stamp.pdf:3' '' in.pdf out.pdf --mode pdf          # page 3 onto every page
pdfcpu2 stamp add 'stamp.pdf' '' in.pdf out.pdf --mode pdf            # multistamp
pdfcpu2 stamp add 'stamp.pdf:2:3' '' in.pdf out.pdf --mode pdf        # multistamp: src page 2 starts at dest page 3

Description string

Defaults "font:Helvetica, points:24, rtl:off, pos:c, off:0,0 scale:0.5 rel, rot:0, d:1, op:1":

Entry Meaning
font: see pdfcpu2 fonts list; script: for CJK without embedding big fonts (Hans, Hant, Hira, Kana, Jpan, Hang, Kore)
points: font size (with absolute scaling only)
pos: anchor tl tc tr l c r bl bc br
off: offset dx dy
scale: 0 < x <= 1 rel or > 0 abs
rot: −180..180, or d:1/d:2 diagonal
op: opacity 0..1
aligntext: l c r j
fillcolor: / strokecolor: / bgcol: colors (RGB triple 1.0 0 0 or #RRGGBB); render mode selects which applies
margins:, border: bounding box styling (with background)
url: add link annotation (stamps only)

update / remove

pdfcpu2 stamp update "APPROVED" "pos:tr, scale:.35 abs, op:.6" in.pdf out.pdf --mode text
pdfcpu2 stamp 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 stamp on top, pages 1-10; onTop=true distinguishes stamp from watermark
	err := api.AddTextWatermarksFile(ctx, "in.pdf", "out.pdf",
		[]string{"1-10"}, true, "CONFIDENTIAL", "pos:tr, scale:.35 abs, op:.6", conf)
	if err != nil {
		panic(err)
	}

	// Image stamp
	err = api.AddImageWatermarksFile(ctx, "in.pdf", "out2.pdf", nil, true, "logo.png", "pos:bl", conf)

	// PDF stamp
	err = api.AddPDFWatermarksFile(ctx, "in.pdf", "out3.pdf", nil, true, "stamp.pdf:3", "", conf)
	_ = err
}

Per-page configurations: api.AddWatermarksMapFile(ctx, inFile, outFile, map[int]*model.Watermark, conf) applies a different stamp to each page (e.g. alternating headers/footers).

Clone this wiki locally