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.

cpdf -add-text "Copyright 2013 ACME Corp." in.pdf -o out.pdf

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.

cpdf -remove-text in.pdf -o out.pdf

Page Numbers

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

%Page      Pagenum berin arabicnotation (1,2,3...)
%%roman     Pagenum berin low er-caseroman notation(i,ii,iii...)
%EndPage   Lastpageofdocumentinarabicnotation
%Label     The pagelabelofthe page
%EndLabel  The pagelabelofthe lastpage
%filename  The fullfilenam eoftheinputdocum ent

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.

Date and Time Formats

%a  Abbreviatedweekdaynam e(Sun,M onetc.)
%A  Fullweekdayname (Sunday,Mondayetc.)
%b  Abbreviatedm onthnam e(Jan,Febetc.)
%B  Fullmonthname (January,Februaryetc.)
%d  Day ofthem onth (01–31)
%e  Day ofthem onth (1–31)
%%HI  HH oouurrinin 2412--hhoouurrcclolocckk((0001–2–132))
%j  Day oftheyear(001–366)
%m  M onth oftheyear(01–12)
%M  M inuteofthehour(00–59)
%p  ”a.m ”or”p.m ”
%S  Secondoftheminute (00–61)
%T  Same as%H :%M :% S
%u  W eekday (1–7,1=M onday)
%w  W eekday (0–6,0=M onday)
%Y  Year(0000–9999)
%%  The% character.

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:

cpdf -add-text "Page ID: %Bates" -bates 23745 in.pdf -o out.pdf

Position

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

-pos-center "200 200"

Position the center of the baseline text at (200pt, 200pt)

-pos-left "200 200"

Position the left of the baseline of the text at (200pt, 200pt)

-pos-right "200 200"

Position the right of the baseline of the text at (200pt, 200pt)

Positions relative to certain common points can be set:

-top 10             Centerofbaseline 10pts downfromthetopcenter
-topleft 10         Leftofbaseline 10 ptsdow nand in from top left
-topright 10        Rightofbaseline 10pts downand leftfrom top right
-left 10            Leftofbaseline 10 ptsinfromcenter left
-bottomleft 10      Leftofbaseline 10 ptsinand upfrom bottom left
-bottom 10          Centerofbaseline 10pts upfrom bottom center
-bottomright 10     Rightofbaseline 10pts upandinfrom bottom righ&
-diagonal           Diagonal,bottom lefttotopright,centeredon page
-reverse-diagonal   Diagonal,bottom righttotopleft,centered

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.

Font and Size

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

Tim es-Rom an
Tim es-Bold
Tim es-Italic
Tim es-BoldItalic
Helvetica
Helvetica-Bold
Helvetica-Oblique
Helvetica-BoldOblique
Courier
CCoouurrieierr-B-Oolbdliqu e
Courier-BoldOblique
Symbol
ZapfD ingbats

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

cpdf -add-text "-%Page-" -font "Times-Italic" in.pdf -o out.pdf

See §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:

cpdf -add-text "-%Page-" -font-size 36 in.pdf -o out.pdf

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

cpdf -add-text "Hullo" -color "red" in.pdf -o out.pdf

cpdf -add-text "Hullo" -color "0.5 0.5 0.5" in.pdf -o out.pdf

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

cpdf -add-text "DRAFT" -color "red" -opacity 0.3 -o out.pdf

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:

cpdf -add-text "DRAFT" -diagonal -outline in.pdf -o out.pdf

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).

cpdf -add-text "Specification\n%Page of %EndPage"  
               -topright 10 in.pdf -o out.pdf

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.

cpdf -add-text "Specification\n%Page of %EndPage"  
               -topright 10 -line-spacing 1.5 in.pdf -o out.pdf

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:

cpdf -add-text "Long line\nShort" -justify-right  
               in.pdf -o out.pdf

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.