Chapter 8
Watermarks and Stamps

8.1 Add a Watermark or Logo

The -stamp-on and -stamp-under operations stamp the first page of a source PDF onto or under each page in the given range of the input file. For example,

stamps the file logo.pdf onto the odd pages of in.pdf, writing to out.pdf. A watermark should go underneath each page:

The position commands in Section 8.2.4 can be used to locate the stamp more precisely (they are calculated relative to the crop box of the stamp). Or, preprocess the stamp with -shift first.

The -scale-stamp-to-fit option can be added to scale the stamp to fit the page before applying it. The use of positioning commands together with -scale-stamp-to-fit is not recommended.

The -combine-pages operation takes two PDF files and stamps each page of one over each page of the other. The length of the output is the same as the length of the “under” file. For instance:

Page attributes (such as the display rotation) are taken from the “under” file. For best results, remove any rotation differences in the two files using -upright first.

The -relative-to-cropbox option takes the positioning command to be relative to the crop box of each page rather than the media box.

8.2 Stamp Text, Dates and Times.

The -add-text operation allows text, dates and times to be stamped over one or more pages of the input at a given position and using a given font, font size and color.

The default is black 12pt Times New Roman text in the top left of each page. The text can be placed underneath rather than over the page by adding the -underneath option.

Text previously added by cpdf may be removed by the -remove-text operation.

8.2.1 Page Numbers

There are various special codes to include the page number in the text:

%Page      Page number in arabic notation (1, 2, 3...)
%roman     Page number in lower-case roman notation (i, ii, iii...)
%Roman     Page number in upper- case roman notation (I, II, III...)
%EndPage   Last page of document in arabic notation
%Label     The page label of the page
%EndLabel  The page label of the last page
%filename  The full file name of the input document

For example, the format "Page %Page of %EndPage" might become ”Page 5 of 17”.

NB: In some circumstances (e.g in batch files) on Microsoft Windows, % is a special character, and must be escaped (written as %%). Consult your local documentation for details.

8.2.2 Date and Time Formats

%a  Abbreviated weekday name (Sun, Mon etc.)
%A  Full weekday name (Sunday, Monday etc.)
%b  Abbreviated month name (Jan, Feb etc.)
%B  Full month name (January, February etc.)
%d  Day of the month (01–31)
%e  Day of the month (1–31)
%H  Hour in 24-hour clock (00–23)
%I  Hour in 12-hour clock (01–12)
%j  Day of the year (001–366)
%m  Month of the year (01–12)
%M  Minute of the hour (00–59)
%p  ”a.m ” or ”p.m”
%S  Second of the minute (00–61)
%T  Same as %H:%M:%S
%u  Weekday (1–7, 1 = Monday)
%w  Weekday (0–6, 0 = Monday)
%Y  Year (0000–9999)
%%  The % character.

8.2.3 Bates Numbers

Unique page identifiers can be specified by putting %Bates in the format. The starting point can be set with the -bates option. For example:

To specify that bates numbering begins at the first page of the range, use -bates-at-range instead. This option must be specified after the range is specified. To pad the bates number up to a given number of leading zeros, use -bates-pad-to in addition to either -bates or -bates-at-range.

8.2.4 Position

The position of the text may be specified either in absolute terms:

Positions relative to certain common points can be set:

No attempt is made to take account of the page rotation when interpreting the position, so -prerotate must be added to the command line if the file contains pages with a non-zero viewing rotation. This is equivalent to pre-processing the document with -upright.

The -relative-to-cropbox modifier can be added to the command line to make these measurements relative to the crop box instead of the media box.

The default position is equivalent to -topleft 100.

The -midline option may be added to specify that the positioning commands above are to be considered relative to the midline of the text, rather than its baseline. Similarly, the -topline option may be used to specify that the position is taken relative to the top of the text.

8.2.5 Font and Size

The font may be set with the -font option. The 14 Standard PDF fonts are available:

TTiimmeess--RBoomldan
Times-Italic
Times-BoldItalic
Helvetica
Helvetica-Bold
Helvetica-Oblique
Helvetica-BoldOblique
Courier
Courier-Bold
Courier-Oblique
Courier-BoldOblique
Symbol
ZapfDingbats

For example, page numbers in Times Italic can be achieved by:

See Section 14.1 for how to use other fonts.

The font size can be altered with the -font-size option, which specifies the size in points:

8.2.6 Colors

The -color option takes an RGB color, where red, green and blue components range between 0 and 1. The following values are predefined:

-Color--R,-G,-B---
 white   1, 1, 1
 black   0, 0, 0
 red     1, 0, 0
 green   0, 1, 0
 blue    0, 0, 1

Partly-transparent text may be specified using the -opacity option. Wholly opaque is 1 and wholly transparent is 0. For example:

8.2.7 Outline Text

The -outline option sets outline text. The line width (default 1pt) may be set with the -linewidth option. For example, to stamp documents as drafts:

8.2.8 Multi-line Text

The code \n can be included in the text string to move to the next line. In this case, the vertical position refers to the baseline of the first line of text (if the position is at the top, top left or top right of the page) or the baseline of the last line of text (if the position is at the bottom, bottom left or bottom right).

The -midline option may be used to make these vertical positions relative to the midline of a line of text rather than the baseline, as usual.

The -line-spacing option can be used to increase or decrease the line spacing, where a spacing of 1 is the standard.

Justification of multiple lines is handled by the -justify-left, -justify-right and
-justify-center options. The defaults are left justification for positions relative to the left hand side of the page, right justification for those relative to the right, and center justification for positions relative to the center of the page. For example:

8.2.9 Special Characters

If your command line allows for the inclusion of unicode characters, the input text will be considered as UTF8 by cpdf. Special characters which exist in the PDF WinAnsiEncoding Latin 1 code (such as many accented characters) will be reproduced in the PDF. This does not mean, however, that every special character can be reproduced. You must experiment.

For compatibility with previous versions of cpdf, special characters may be introduced manually with a backslash followed by the three-digit octal code of the character in the PDF WinAnsiEncoding Latin 1 Code. The full table is included in Appendix D of the Adobe PDF Reference Manual, which is available at http://www.adobe.com/devnet/pdf/pdf_reference.html.

For example, a German sharp s (ß) may be introduced by \337.

8.3 Stamping Graphics

A rectangle may be placed on one or more pages by using the -add-rectangle <size> command. Most of the options discussed above for text placement apply in the same way. For example:

This can be used to blank out or highlight part of the document. The following positioning options work as you would expect: -topleft, -top, -topright, -right, -bottomright, -bottom, -bottomleft, -left, -center. When using the option -pos-left "x y", the point (x, y) refers to the bottom-left of the rectangle. When using the option -pos-right "x y", the point (x, y) refers to the bottom-right of the rectangle. When using the option -pos-center "x y", the point (x, y) refers to the center of the rectangle. The options -diagonal and -reverse-diagonal have no meaning.