Watermark
Watermarks are text or image overlays on a web page or application that prevent content from being used or passed around without permission. They are generated dynamically and offer a number of configuration options.
Use the Watermark Generator to preview watermark styles and download the plugin configuration as JSON.
Plugin mode
Installation
pnpm add @univerjs/watermarknpm install @univerjs/watermarkyarn add @univerjs/watermarkbun add @univerjs/watermarkUsage
import { UniverWatermarkPlugin } from '@univerjs/watermark'import '@univerjs/watermark/facade'const univer = new Univer({ // ...})univer.registerPlugin(UniverWatermarkPlugin, { textWatermarkSettings: { content: 'Hello, Univer!', fontSize: 36, }, })Plugin configuration
Pass one of the objects below to UniverWatermarkPlugin. If more than one is passed, user information takes precedence over text, and text takes precedence over the image. Default values take effect once the matching object is passed.
userWatermarkSettingsobjectWatermark with the current user’s information.namebooleanDefault:trueIncludes the current user's name.emailbooleanDefault:falseIncludes the current user's email address.phonebooleanDefault:falseIncludes the current user's phone number.uidbooleanDefault:falseIncludes the current user's ID.fontSizenumberDefault:16Font size in pixels.colorstringDefault:'rgb(0,0,0)'Text color. Accepts a CSS color.boldbooleanDefault:falseUses bold text.italicbooleanDefault:falseUses italic text.direction'ltr' | 'rtl' | 'inherit'Default:'ltr'Sets the text direction.xnumberDefault:60Initial horizontal offset in pixels.ynumberDefault:60Initial vertical offset in pixels.repeatbooleanDefault:trueTiles the watermark across the editor.spacingXnumberDefault:200Horizontal repeat spacing in pixels.spacingYnumberDefault:100Vertical repeat spacing in pixels.rotatenumberDefault:-30Rotation in degrees.opacitynumberDefault:0.15Opacity from 0 to 1.
textWatermarkSettingsobjectText watermark.contentstringDefault:''Text to display.fontSizenumberDefault:16Font size in pixels.colorstringDefault:'rgb(0,0,0)'Text color. Accepts a CSS color.boldbooleanDefault:falseUses bold text.italicbooleanDefault:falseUses italic text.direction'ltr' | 'rtl' | 'inherit'Default:'ltr'Sets the text direction.xnumberDefault:60Initial horizontal offset in pixels.ynumberDefault:36Initial vertical offset in pixels.repeatbooleanDefault:trueTiles the watermark across the editor.spacingXnumberDefault:200Horizontal repeat spacing in pixels.spacingYnumberDefault:100Vertical repeat spacing in pixels.rotatenumberDefault:0Rotation in degrees.opacitynumberDefault:0.15Opacity from 0 to 1.
imageWatermarkSettingsobjectImage watermark.urlstringDefault:''URL of the watermark image.widthnumberDefault:100Image width in pixels.heightnumberDefault:100Image height in pixels when aspect ratio is unlocked.maintainAspectRatiobooleanDefault:trueCalculates height from width andoriginRatio.originRationumberDefault:1Original image width divided by its height.xnumberDefault:60Initial horizontal offset in pixels.ynumberDefault:36Initial vertical offset in pixels.repeatbooleanDefault:trueTiles the watermark across the editor.spacingXnumberDefault:200Horizontal repeat spacing in pixels.spacingYnumberDefault:100Vertical repeat spacing in pixels.rotatenumberDefault:0Rotation in degrees.opacitynumberDefault:0.15Opacity from 0 to 1.
Preset mode
No watermark preset exists, but the plugin can be registered alongside your presets.
Installation
pnpm add @univerjs/watermarknpm install @univerjs/watermarkyarn add @univerjs/watermarkbun add @univerjs/watermarkUsage
import { UniverWatermarkPlugin } from '@univerjs/watermark'import '@univerjs/watermark/facade'const { univerAPI } = createUniver({ // ... presets: [ UniverDocsCorePreset(), ], plugins: [ [UniverWatermarkPlugin, { textWatermarkSettings: { content: 'Hello, Univer!', fontSize: 36, }, }], ],})Facade API
Importing
Plugin mode note
Only plugin mode requires a manual Facade import. Preset mode already bundles the Facade package, so no additional import is needed.
import '@univerjs/watermark/facade'Set watermark
univerAPI.addWatermark('text', { content: 'hello', repeat: true })Remove watermark
univerAPI.deleteWatermark()How is this guide?