watermark
Watermark PDF
Stamp text or a logo across the pages, at a chosen angle and opacity.
- Reads
- a PDF — application/pdf
- Writes
- one file — PDFs
- Tool page
- /watermark-pdf
Example
Mark a circulating draft so nobody mistakes it for the final one.
Given
- draft.pdf — an ordinary PDF of 3 pages
From code
import { loadDocument, runOperation } from '@pagecraft/core';
const draft = await loadDocument({ bytes, name: 'draft.pdf' });
const [output] = await runOperation('watermark', [draft], {
kind: 'text',
text: 'DRAFT',
opacity: 0.15,
rotation: 45,
});
From a shell
pagecraft watermark draft.pdf --kind text --text DRAFT --opacity 0.15 --rotation 45
What comes back
One PDF of 3 pages, containing “DRAFT”.
This example is run by the test suite. If it stopped being true, the build would fail.
Options
kind--kind
string, one of
Watermark
Default: 'text'
text— Textimage— A picture
text--text
string
Text
What the watermark says.
Only when kind is 'text'.
Default: 'DRAFT'
image--image
Uint8Array
Picture
A logo or a stamp to lay on the page instead of text.
Only when kind is 'image'.
scale--scale
number (%)
Size
How wide the picture is drawn, as a share of the page width.
Only when kind is 'image'.
Default: 40
font--font
string, one of
Typeface
Default: 'sans'
sans— Helvetica.serif— Times.mono— Courier.
bold--bold
boolean
Bold
Default: false
italic--italic
boolean
Italic
Default: false
fontFile--font-file
Uint8Array
Font file
A TrueType or OpenType font to set the text in. Needed for scripts the built-in fonts do not cover, unless the host supplies one.
size--size
number (pt)
Size
Only when kind is 'text'.
Default: 48
color--color
string, '#rrggbb'
Colour
Only when kind is 'text'.
Default: '#808080'
opacity--opacity
number
Opacity
How much of the page shows through. 1 is solid.
Default: 0.15
rotation--rotation
number (°)
Angle
Default: 45
position--position
string, one of
Position
Default: 'middle-center'
top-left— Top lefttop-center— Top centretop-right— Top rightmiddle-left— Middle leftmiddle-center— Centremiddle-right— Middle rightbottom-left— Bottom leftbottom-center— Bottom centrebottom-right— Bottom right
tile--tile
boolean
Repeat across the page
Covers the whole page with the stamp instead of placing it once.
Default: false
gap--gap
number
Gap
Space between repeats.
Only when tile is on.
Default: 15
margin--margin
number
Margin
How far in from the edge the stamp sits. Ignored when it repeats.
Default: 10
unit--unit
string, one of
Measured in
Default: 'mm'
mm— Millimetrescm— Centimetresin— Inchespt— Points
placement--placement
string, one of
Placement
Default: 'over'
over— Over the contentunder— The page’s own text and pictures stay in front of the stamp.
pages--pages
string, a page selection: '1-3, 7, 9-', 'even', 'last'
Pages
Default: 'all'
What it cannot do
- A stamp placed under the content is hidden by anything opaque already painted over that part of the page — a scan, or a full-bleed background.
- A repeated stamp is spaced no more finely than a sixtieth of the sheet, so a very small stamp is spread further apart rather than repeated tens of thousands of times.
- Shaping and joining come from the font itself, and nothing reorders a line: text is drawn in the order it is given, so a line mixing right-to-left and left-to-right writing comes out in that order rather than in reading order.