Watermark
A watermark is a text or image overlay drawn on top of a spreadsheet. The content, starting position, repeat spacing, rotation, and opacity are configurable.
The Watermark Generator previews watermark styles and downloads 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 object is passed, user information takes precedence over text, and text takes precedence over image. The default values apply when the matching object is passed.
userWatermarkSettingsobjectWatermark that displays 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:1Width of the original image 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
Watermark has no preset of its own, but the plugin still works alongside 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: [ UniverSheetsCorePreset(), ], plugins: [ [UniverWatermarkPlugin, { textWatermarkSettings: { content: 'Hello, Univer!', fontSize: 36, }, }], ],})Facade API
Importing
Plugin mode note
Only plugin mode requires manually importing the Facade package. Preset mode already includes the corresponding Facade package, so no additional import is required.
import '@univerjs/watermark/facade'Set watermark
univerAPI.addWatermark('text', { content: 'hello', repeat: true })Remove watermark
univerAPI.deleteWatermark()How is this guide?