pdfcpu

Logo

A PDF processor written in Go.

View the Project on GitHub pdfcpu/pdfcpu


Changelog

Watermark

Add a watermark to selected pages of inFile. Have a look at some examples.

Watermarks may be stacked on top of each other. This allows for producing more complex page stamps - a mixture of text, images and foreign PDF page content. Using description you can configure various aspects like position, offset, rotation, scaling and opacity. For text based watermarks you can also configure font name, font size, fill color and render mode.


WARNING
A watermark resides in the background of a page. How much of the watermark will be rendered visible on a page depends on the layers on top and the transparency involved. This applies to PDF in general. Eg. scanned PDF files usually consist of bitmap images spanning whole pages and will hide anything in the background including any watermark. For these cases use pdfcpu stamp with an opacity < 1 instead to get a similar result.


Usage

pdfcpu watermark add    string | file description inFile [ outFile ] [flags]
pdfcpu watermark update string | file description inFile [ outFile ] [flags]
pdfcpu watermark remove inFile [ outFile ] [flags]

NOTE
In the Adobe world a watermark is text or an image that appears either in front of or behind existing document content, unlike a stamp comment aka stamp annotation that anybody reading the PDF can open, edit, move around and delete. The difference here is that a watermark is integrated into a PDF page as a fixed element. Within pdfcpu the meaning of these terms is slightly different:

where content may be text, an image or a PDF page.



Flags

flagdescriptionrequired
p(ages)selected pagesno
m(ode)text, image or pdfyes

Common Flags


Arguments

namedescriptionrequired
stringdisplay stringfor text stamps
filefile namefor image or pdf stamps
descriptionconfiguration stringyes
inFilePDF input fileyes
outFilePDF output fileno

Description

A configuration string to specify watermark parameters.

You may use parameter prefixes as long as the parameter can be identified. eg. o: .7 is ambiguous because there is opacity and offset but op: .7 will do the job.

parameterdescriptionvaluesdefault
fontnamea basefontPlease refer to pdfcpu fonts listHelvetica
scriptnameISO-15924 codeHans, Hant, Hira, Kana, Jpan, Hang, Kore
pointsfontsize in pointsin combination with absolute scaling only24
rtlright to left userfonton/off, true/false, t/foff
positionthe stamps lower left corneranchors: tl, tc, tr, l, c, r, bl, bc, brc
offset(dx,dy) float vals in user unitseg. ‘15 20’ or ‘15.0 20.0’0 0
scalefactor0.0 < i <= 1.0 followed by optional abs or rel0.5 rel
aligntexthorizontal text alignmentl..left, c..center, r..right, j..justifiedc
strokecolorfor rendering text (see mode)color0.5 0.5 0.5 = gray
fillcolor, colorfor rendering text (see mode)color0.5 0.5 0.5 = gray
backgroundcolor, bgcolorbounding box backgroundcolornone
rotationrotation angle-180.0 <= i <= 180.00.0
diagonalrender along diagonal1 .. lower left to upper right1
2 .. upper left to lower right
opacity0.0 <= i <= 1.01
mode, rendermodeapply fill color0 .. fill0
apply stroke color1 .. stroke
apply both fill & stroke color2 .. fill & stroke
marginsbounding box margins for texti .. set all four margins0
requires bgcolori j .. set t/b margins to i, set l/r margins to j
i j k .. set top to i, left/right to j, bot to k
i j k l .. set top, right, bottom, left margins
borderbounding box border for texti {round} {color}0
requires bccolori .. border width > 0
round .. set round bounding box corners
color .. border color

Only one of rotation and diagonal is allowed.

The following description parameters are for text based watermarks only:


Anchors for positioning

leftcenterright
toptltctr
lcr
bottomblbcbr

Default description

'f:Helvetica, points:24, rtl:off, scale:0.5 rel, pos:c, off:0 0, align:c, fillc:#808080, strokec:#808080, rot:0, d:1, op:1, mo:0, ma:0, bo:0'

The default watermark configuration is:

In addition for text based watermarks:

You only have to specify parameters that differ from the default.

Examples

Text Based Watermarks

Create a watermark using defaults only:

$ pdfcpu watermark add 'This is a watermark' '' in.pdf out.pdf --mode text


Create a watermark using scale factor 1:
$ pdfcpu watermark add --mode text -- 'This is a watermark' 'scale:1' in.pdf out.pdf

       


Create a watermark along the second diagonale using scale factor 0.9, default render mode fill and a fill color:

$ pdfcpu watermark add 'This is a watermark' 'scale:.9, d:2, c:.6 .2 .9' in.pdf out.pdf -m text


Create a watermark with 0 degree rotation using scale factor 0.9 and render mode stroke:

$ pdfcpu watermark add 'This is a watermark' 'scale:.9, rot:0, mo:1' in.pdf out.pdf --mode text


Create a watermark with a counterclockwise rotation of 45 degrees using scale factor 1, render mode fill & stroke and a fill color:

$ pdfcpu watermark add 'This is a watermark' 'scale:1, rot:45, mo:2, c:.2 .7 .9' in.pdf out.pdf --mode text


Create a watermark using some multi line text, show its bounding box by setting bgcol, set all margins to 5 and a border width of 7 rendering round corners.

$ pdfcpu watermark add 'Some multi\nline text' 'ma:5, bo:7 round .3 .7 .7, fillc:#3277d3, bgcol:#beded9, rot:0' in.pdf out.pdf -m text


Create a watermark with default rotation, using scale factor 1, font size 48, default render mode fill, a fill color and set opacity to 0.6:

$ pdfcpu watermark add 'Draft' 'points:48, scale:1, color:.8 .8 .4, op:.6' in.pdf out.pdf --mode text


Let's assume we have a PDF where even pages are blank. We can add a watermark for theses pages saying "Intentionally left blank" like so:
$ pdfcpu watermark add 'Intentionally left blank' '' in.pdf out.pdf --mode text --pages even 

We also could have used pdfcpu stamp. There is really no difference since we apply only to empty pages here.


Image Based Watermarks

Create a watermark using defaults only:

$ pdfcpu watermark add 'pic.jpg' '' in.pdf out.pdf -m image


Create a watermark using 0 degree rotation and relative scaling of 1.0:

$ pdfcpu watermark add 'pic.jpg' 'scale:1 rel, rot:0' in.pdf out.pdf --mode image


Create a watermark using 0 degree rotation and absolute scaling of 1.0:

$ pdfcpu watermark add 'pic.jpg' 'scale:1 abs, rot:0' in.pdf out.pdf -m image


Create a watermark using a clockwise rotation of 30 degrees and absolute scaling of 1.0:

$ pdfcpu watermark add --mode image -- 'pic.jpg' 'rotation:-30, scalefactor:1 abs' in.pdf out.pdf


Create a watermark using a clockwise rotation of 30 degrees and absolute scaling of 0.25:

$ pdfcpu watermark add -m image -- 'pic.jpg' 'rot:-30, scale:.25 abs' in.pdf out.pdf

PDF Based Watermarks

Create a watermark using defaults only. This will apply page 1 of some.pdf:

$ pdfcpu watermark add 'some.pdf:1' '' in.pdf out.pdf --mode pdf


This is how to create a watermark using defaults and page 2 of some.pdf:

$ pdfcpu watermark add 'some.pdf:2' '' in.pdf out.pdf -m pdf