PDFDispatch Docs

Watermark and stamp

A watermark goes behind the page content, a stamp on top of it. Both can be text, an image or a page of another PDF.

POST https://api.pdfdispatch.com/v1/pdf/watermark

POST https://api.pdfdispatch.com/v1/pdf/stamp

Form fields

The two routes are the same except for the prefix: watermark... on the first, stamp... on the second.

FieldTypeDefaultWhat it does
files requiredfile(s)–The PDFs to mark.
watermarkSource / stampSource requiredstring–text, image or pdf.
watermarkExpression / stampExpressionstring–For text, the text itself. For image and pdf, leave it out and send the file instead (below).
watermark / stampfile–The image (PNG, JPEG, …) or PDF to draw, as a file part with this name.
watermarkPages / stampPagesstring–Only these pages, for example 1, 2-, odd. All pages without it.
watermarkOptions / stampOptionsJSON object–How it looks; see the table below.

To apply several in one request, repeat the fields: the first stampSource goes with the first stampExpression, stampPages and stampOptions, the second with the second, and so on. Image and PDF entries take the uploaded stamp (or watermark) files in order. The same fields work on every conversion route.

Options

watermarkOptions and stampOptions are a JSON object of the keys below. Every value is a string, numbers too ("points": "48", not "points": 48); a bare number is refused with 400. Leave out what you do not need.

KeyTypeDefaultWhat it does
fontnamestringHelveticaOne of the 14 standard PDF fonts: Helvetica, Times-Roman, Courier, their -Bold and -Oblique (or -Italic) forms, Symbol, ZapfDingbats.
pointsnumber24Font size.
scalefactorstring0.5 relSize as a share of the page: 0.5 rel is half the page width; 1 abs keeps the natural size.
rotationnumber–Angle in degrees, counter-clockwise. Without it, the mark runs along the diagonal (see diagonal): send "0" for a level stamp or logo.
diagonalinteger11 from bottom left to top right, 2 from top left to bottom right.
positionstringcWhere on the page: c (centre), tl, tc, tr, l, r, bl, bc, br.
offsetstring0 0Move it from that position, in points: "-20 30".
fillcolorcolour#808080Text colour, as #rrggbb or a name such as red.
opacitynumber1From 0 (invisible) to 1 (solid).
aligntextstringcenterleft, center, right or justify, for text over several lines (\n in the expression).
backgroundcolor, bordercolor, border, marginsvarious–A box behind the text, with its colour, border and spacing.

Examples

“DRAFT” diagonally behind every page:

curl --fail-with-body \
  --header "Authorization: Bearer $PDD_KEY" \
  --form files=@contract.pdf \
  --form watermarkSource=text \
  --form watermarkExpression=DRAFT \
  --form 'watermarkOptions={"fontname": "Helvetica-Bold", "points": "96", "fillcolor": "#c2410c", "opacity": "0.15"}' \
  --output contract-draft.pdf \
  https://api.pdfdispatch.com/v1/pdf/watermark

A “PAID” stamp in the top right corner of the first page, and a logo at the bottom of every page, in one request:

curl --fail-with-body \
  --header "Authorization: Bearer $PDD_KEY" \
  --form files=@invoice.pdf \
  --form stampSource=text \
  --form stampExpression=PAID \
  --form stampPages=1 \
  --form 'stampOptions={"position": "tr", "offset": "-40 -40", "rotation": "15", "points": "28", "fillcolor": "#15803d", "scalefactor": "1 abs"}' \
  --form stampSource=image \
  --form 'stampOptions={"position": "bc", "rotation": "0", "scalefactor": "0.15 rel", "offset": "0 20"}' \
  --form stamp=@logo.png \
  --output invoice-paid.pdf \
  https://api.pdfdispatch.com/v1/pdf/stamp

Fields are matched by position. The second entry has no stampExpression and no stampPages, which works because nothing comes after it. When an earlier entry has no value for a field that a later one uses, send that field empty for it (--form stampPages=), so the positions still line up.

For Office files, the Office route can also draw a simple text watermark itself while converting (nativeWatermarkText, see Office documents).