pdfcpu

Logo

A PDF processor written in Go.

View the Project on GitHub pdfcpu/pdfcpu


Changelog

Stamp

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

Stamps 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 stamps you can also configure font name, font size, fill color and render mode.

Usage

pdfcpu stamp add    string | file description inFile [ outFile ] [flags]
pdfcpu stamp update string | file description inFile [ outFile ] [flags]
pdfcpu stamp 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

Special note for text stamps:

Use the following format strings:

$ pdfcpu stamp add --mode text -- 'Page %p of %P' 'scale:1.0 abs, pos:bc, rot:0' in.pdf out.pdf

Special note for PDF stamps:

If you want to use a specific page as your stamp, specify the page number after the stamp file and use ‘:’ as separator:

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

You can also apply a multistamp. This means you repeatedly apply stamp.pdf’s pages to stamp pages of in.pdf in an orderly fashion. If in.pdf has more pages than stamp.pdf, the last page of stamp.pdf gets applied for the remaining pages. Omit the stamp page number for multi stamping:

$ pdfcpu stamp add 'stamp.pdf' '' in.pdf out.pdf -m pdf

You can also customize your multistamp. If you want to start multistamping at page 2 of your stamp file and page 3 of your input file you can do the following:
$ pdfcpu stamp add 'stamp.pdf:2:3' '' in.pdf out.pdf --mode pdf

Description

A configuration string to specify the stamp 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
backgroundcolorbounding box backgroundcolor
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
urladd link annotationOmit https://

Only one of rotation and diagonal is allowed.

The following description parameters are for text based stamps 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 stamp configuration is:

In addition for text based stamps:

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


Examples

Text Based Stamps

Create a stamp using defaults only:

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


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

       


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

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


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

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


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

$ pdfcpu stamp add 'This is a stamp' 'scale:1, rot:45, mode:2, color:.2 .7 .9' in.pdf out.pdf -m text


Create a stamp of 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 stamp add 'Some multi\nline text' 'ma:5, bo:7 round .3 .7 .7, fillc:#3277d3, bgcol:#beded9, rot:0' in.pdf out.pdf --mode text


Create a stamp with default rotation, using scale factor 1, font size 48, default render mode fill, a fill color and increasing opacity from 0.3 to 1. By setting an opacity < 1 you can fake a watermark. This may be useful in scenarios where pdfcpu watermark does not produce satisfying results for a particular PDF file:

$ pdfcpu stamp add 'Draft' 'points:48, scale:1, fillc:.8 .8 .4, op:.3' in1.pdf out1.pdf -m text
$ pdfcpu stamp add 'Draft' 'points:48, scale:1, fillc:.8 .8 .4, op:0.6' in2.pdf out2.pdf -m text
$ pdfcpu stamp add 'Draft' 'points:48, scale:1, fillc:.8 .8 .4, op:1' in3.pdf out3.pdf -m text

   


Image Based Stamps

Create a stamp using defaults only:

$ pdfcpu stamp add 'pic.jpg' '' in.pdf out.pdf --mode image


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

$ pdfcpu stamp add 'pic.jpg' 'scalef:1 rel, rot:0' in.pdf out.pdf -m image


PDF Based Stamps

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

$ pdfcpu stamp add 'some.pdf:1' '' in.pdf out.pdf -m pdf


Create a multi stamp using stamp.pdf, apply a 0 degree rotation and 0.3 relative scaling.

Page 1 of in.pdf gets stamped with page 1 of stamp.pdf, page 2 of in.pdf gets stamped with page 2 of stamp.pdf and so forth.

$ pdfcpu stamp add 'stamp.pdf' 'rot:0, scale:.3 rel' in.pdf out.pdf --mode pdf


Stamp Lifecycle

Create a stamp using the default options.

$ pdfcpu stamp add 'Draft' '' template.pdf work.pdf -m text


Let’s edit the stamps color, render mode and opacity

$ pdfcpu stamp update 'Draft' 'c: .2 .6 .5, rendermode:2, op:.7' work.pdf -m text


We add a centered footer on the bottom of the page.

$ pdfcpu stamp add 'Footer' 'pos:bc, scale: 1.0 abs, rot:0, c: .5 .5 .9' work.pdf --mode text


Let’s add a logo in the top right corner.

$ pdfcpu stamp add --mode image -- 'logo.png' 'pos:tr, rot:0, scale:.2' work.pdf


Let’s get rid of the stamp on page 1

$ pdfcpu stamp remove -pages 1 work.pdf

Finally let’s remove all stamps of this file.

$ pdfcpu stamp remove work.pdf

Userfonts

Let’s create a Unicode text stamp using a user font:

  1. Choose your favorite TrueType font or collection.
  2. Follow the instructions to install the font you would like to use.

Left-to-right, Simple Chinese

$ pdfcpu stamp add '这是一个测试' 'fo:SimSun' in.pdf out.pdf -m text
writing out.pdf...
pages: all

TODO: Explain avoiding font embedding for CJK fonts by configuring scriptname

Right-to-left, Arabic

$ pdfcpu stamp add 'هذا اختبار' 'rtl:true, fo:UnifontMedium' in.pdf out.pdf -m text
writing out.pdf...
pages: all