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    [-v(erbose)|vv] [-q(uiet)] [-pages selectedPages] [-upw userpw] [-opw ownerpw] description inFile [outFile]
pdfcpu watermark remove [-v(erbose)|vv] [-q(uiet)] [-pages selectedPages] [-upw userpw] [-opw ownerpw] inFile [outFile]
pdfcpu watermark update [-v(erbose)|vv] [-q(uiet)] [-pages selectedPages] [-upw userpw] [-opw ownerpw] description inFile [outFile]

NOTE
In the Adobe world a watermark is text or an image that appears either in front of or behind existing document content, like 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

flag description required
verbose turn on logging no
vv verbose logging no
quiet quiet mode no
pages page selection no
upw user password no
opw owner password no


Arguments

name description required default
description configuration string yes  
inFile PDF input file yes  
outFile PDF output file no inFile_new.pdf


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.

The first entry of the description configures the type. It is one of the following:

parameter description values default
fontname a basefont Helvetica, Times-Roman, Courier font: Helvetica
points fontsize in points in combination with absolute scaling only points: 24
position the stamps lower left corner one of full or the anchors: tl, tc, tr, l, c, r, bl, bc, br pos: c
offset   (dx,dy) in user units eg. ‘15 20’ off: 0 0
scalefactor   0.0 < i <= 1.0 followed by optional abs or rel s: 0.5 rel
color 3 fill color intensities 0.0 <= r,g,b <= 1.0, eg. 1.0, 0.0 0.0 = red c: 0.5 0.5 0.5 = gray
rotation rotation angle -180.0 <= i <= 180.0 rot: 0.0
diagonal render along diagonal 1 .. lower left to upper right d:1
    2 .. upper left to lower right  
opacity   0.0 <= i <= 1.0 op:1
mode, rendermode   0 .. fill m:0
    1 .. stroke  
    2 .. fill & stroke  

Only one of rotation and diagonal is allowed.

The following description parameters are for text based watermarks only:


Anchors for positioning

       
  left center right
top tl tc tr
  l c r
bottom bl bc br


Default description

'f:Helvetica, points:24, s:0.5 rel, pos:c, off:0 0, c:0.5 0.5 0.5, rot:0, d:1, o:1, m: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 add watermark 'This is a watermark' test.pdf out.pdf


Create a watermark using scale factor 1:

pdfcpu add watermark 'This is a watermark, s:1' test.pdf out.pdf

       


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

pdfcpu add watermark 'This is a watermark, s:.9, d:2, c:.6 .2 .9' test.pdf out.pdf


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

pdfcpu add watermark 'This is a watermark, s:.9, rot:0, m:1' test.pdf out.pdf


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

pdfcpu add watermark 'This is a watermark, s:1, rot:45, m:2, c:.2 .7 .9' test.pdf out.pdf


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 add watermark 'Draft, points:48, scale:1, color:.8 .8 .4, op:.6' test.pdf out.pdf


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 add watermark -pages even 'Intentionally left blank" test.pdf out.pdf

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 add watermark 'pic.jpg' test.pdf out.pdf


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

pdfcpu add watermark 'pic.jpg, s:1 rel, rot:0' test.pdf out.pdf


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

pdfcpu add watermark 'pic.jpg, s:1 abs, rot:0' test.pdf out.pdf


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

pdfcpu add watermark 'pic.jpg, rotation:-30, scalefactor:1 abs' test.pdf out.pdf


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

pdfcpu add watermark 'pic.jpg, rot:-30, s:.25 abs' test.pdf out.pdf

PDF Based Watermarks

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

pdfcpu add watermark 'some.pdf' test.pdf out.pdf


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

pdfcpu watermark 'some.pdf:2' test.pdf out.pdf