Watermark & Password
This page describes how to add watermarks and how to validate passwords when loading protected documents.
Watermark Protection
Configure the document watermark via props.watermark. The watermark is drawn over the page canvas. Parameters:
text:String, watermark text (recommended ≤ 30 characters)columns:Number, column count (default4)rows:Number, row count (default4)color:String, font color (default'rgba(0, 0, 0, 0.2)'; any valid CSS color)rotation:Number, rotation angle (default30)fontSize:Number, font size (default12 * window.devicePixelRatio; unit: px)
Example:
const options = ref({
watermark: {
text: 'Internal document, do not leak',
columns: 3,
rows: 3,
color: 'rgba(0, 0, 0, 0.1)',
rotation: 25,
},
})Password
When previewing a protected document, the viewer will guide the user to enter a password and validate it:
needPassword: booleanonValidatePassword(password) => boolean | Promise<boolean>
Workflow (simplified):
- During loading, if a password is required, the viewer sets
state.needPassword = trueand waits for user input. - It validates the input using the configured
onValidatePassword. - After validation succeeds, it continues loading the document with the password; when loading finishes, it emits the
loadedevent.
const options = ref({
needPassword: true,
// Tip: do not hardcode passwords in frontend code. Put validation on the server and use sessions/tokens; the frontend should only collect input and show feedback.
onValidatePassword: (password) => password === '1234',
})