Watermark
Renders a large, semi-transparent text watermark as a styled paragraph. Best placed in a section header or footer.
Import
import { watermarkPlugin, type WatermarkOptions } from 'docx-kit'Options
| Option | Type | Default | Description |
|---|---|---|---|
text | string | (required) | Watermark text |
alignment | AlignmentType | CENTER | Horizontal alignment |
color | string | 'BFBFBF' | Text color in hex RRGGBB |
fontSize | number | 48 | Font size in half-points (48 = 24pt) |
Examples
Basic Watermark
import { createDocx, watermarkPlugin } from 'docx-kit/node'
const doc = createDocx()
.use(watermarkPlugin())
.h1('Confidential Document')
.p('This document contains proprietary information.')
.plugin('watermark', { text: 'CONFIDENTIAL' })
.save('confidential.docx')Red DRAFT Watermark
const doc = createDocx()
.use(watermarkPlugin())
.h1('Work in Progress')
.p('This document is still under review.')
.plugin('watermark', {
text: 'DRAFT',
color: 'FF0000',
fontSize: 72, // 36pt
})
.save('draft.docx')Left-Aligned Watermark
import { AlignmentType } from 'docx'
const doc = createDocx()
.use(watermarkPlugin())
.h1('Internal Memo')
.plugin('watermark', {
text: 'INTERNAL USE ONLY',
alignment: AlignmentType.LEFT,
color: '999999',
})
.save('internal.docx')In Section Header/Footer
For a true document-wide watermark, place it in a header or footer:
const doc = createDocx()
.use(watermarkPlugin())
// Render watermark in a footer that applies to all pages
const wm = doc.plugin('watermark', {
text: 'SAMPLE',
color: 'D0D0D0',
fontSize: 60,
})
// Note: The exact header/footer integration depends on
// how sections are configured in your document.Multiple Watermarks
const doc = createDocx()
.use(watermarkPlugin())
.h1('Review Document')
.plugin('watermark', { text: 'DRAFT', color: 'FF6600' })
.p('Please review the following content carefully.')
.pageBreak()
.plugin('watermark', { text: 'CONFIDENTIAL', color: 'CC0000' })
.p('This section contains confidential financial data.')
.save('multi-watermark.docx')Style customization
Pass { styles } to the factory for instance defaults, and options.styles for invocation overrides. The package and docx-kit entry points export WatermarkConfig and WatermarkStyles. Priority: built-in/theme defaults → initialization styles → common node style → invocation part styles. Nested fields merge; arrays replace; undefined retains defaults; 0 and false apply. Units and theme tokens such as $colors.primary are supported.
| Parts | Style type | Scope |
|---|---|---|
text | TextStyleRule | Run typography |
paragraph | ParagraphStyleRule | Background, borders, alignment, spacing and flow |
watermarkPlugin({
styles: { text: { color: '#2563EB', fontSize: 14 } },
})Use the same part names in options.styles for a single call. JSON DSL, AI tool schemas and MCP validation share these contracts; unknown parts and misplaced properties are rejected.