What's new
Image overlay / watermark
Editor.AddImage places PNG or JPEG images on any page as PDF Image XObjects — with a grayscale SMask for alpha, an ExtGState for opacity, and a rotation/scale cm matrix. The same image is written once and shared by every page that references it.
logo, _ := pdf.LoadImage("logo.png")
ed := pdf.NewEditor(data)
for i := 0; i < doc.NumPages(); i++ {
mb := doc.Page(i).MediaBox()
ed.AddImage(pdf.ImageOverlay{
Page: i,
Image: logo,
CX: (mb[0] + mb[2]) / 2,
CY: (mb[1] + mb[3]) / 2,
Width: 400, Height: 140,
Rotation: 45,
Opacity: 0.15,
})
}
result, _ := ed.Apply()cmd/watermark CLI
One-shot diagonal watermarking for the common case:
go run ./cmd/watermark -i in.pdf -img logo.png -o out.pdf \
-angle 45 -opacity 0.15 -scale 0.85
Sizes the image so its rotated bounding box fits within both page dimensions at any angle (corrected during review — earlier draft only constrained the horizontal projection).
Editor.Document() accessor
Returns the parsed PDF, opened lazily on first call and shared across Apply / RedactText / external callers — eliminates the 2–3× re-parsing that previously occurred when callers needed page info before applying edits.
New API
pdf.Image— decoded raster, holding RGB + optional grayscale alphapdf.LoadImage(path)/pdf.LoadImageBytes(data)— PNG / JPEG decoderspdf.ImageOverlay— page, image, center, size, rotation, opacityEditor.AddImage(overlay)— register an overlayEditor.Document()— shared parsed document
- Add image watermark overlay to Editor by @razvandimescu in #12
Full Changelog: v0.8.5...v0.9.0