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    [-v(erbose)|vv] [-q(uiet)] [-pages selectedPages] [-upw userpw] [-opw ownerpw] -mode text|image|pdf string|file description inFile [outFile]
pdfcpu stamp remove [-v(erbose)|vv] [-q(uiet)] [-pages selectedPages] [-upw userpw] [-opw ownerpw] inFile [outFile]
pdfcpu stamp update [-v(erbose)|vv] [-q(uiet)] [-pages selectedPages] [-upw userpw] [-opw ownerpw] -mode text|image|pdf string|file 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
mode text, image or pdf yes


Arguments

name description required
string display string for text stamps
file file name for image or pdf stamps
description configuration string yes
inFile PDF input file yes
outFile PDF output file no


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.

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 stamps 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, op:1, m: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 -mode text 'This is a stamp' '' test.pdf out.pdf


Create a stamp using scale factor 1:

pdfcpu stamp add 'This is a stamp, s:1' test.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 -mode text 'This is a stamp' 's:.9, d:2, c:.6 .2 .9' test.pdf out.pdf


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

pdfcpu stamp add -mode text 'This is a stamp' 's:.9, rot:0, m:1' test.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 -mode text 'This is a stamp' 'scale:1, rot:45, mode:2, color:.2 .7 .9' test.pdf out.pdf


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 -mode text 'Draft' 'points:48, s:1, c:.8 .8 .4, op:.3' test.pdf out1.pdf
pdfcpu stamp add -mode text 'Draft' 'points:48, s:1, c:.8 .8 .4, op:0.6' test.pdf out2.pdf
pdfcpu stamp add -mode text 'Draft' 'points:48, s:1, c:.8 .8 .4, op:1' test.pdf out3.pdf

   


Image Based Stamps

Create a stamp using defaults only:

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


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

pdfcpu stamp add -mode image 'pic.jpg' 'scalef:1 rel, rot:0' test.pdf out.pdf


PDF Based Stamps

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

pdfcpu stamp add -mode pdf 'some.pdf' '' test.pdf out.pdf


Create a stamp using defaults and page 2 of some.pdf, apply a 0 degree rotation and 0.3 relative scaling:

pdfcpu stamp add -mode pdf 'some.pdf:2' 'rot:0, scalef:.3' test.pdf out.pdf


Stamp Lifecycle

Create a stamp using the default options.

pdfcpu stamp add -mode text 'Draft' '' template.pdf work.pdf


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

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


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

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


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

pdfcpu stamp add -mode image 'logo.png' 'pos:tr, rot:0, s:.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