This endpoint adds a watermark to your document.
Each successful call to this endpoint counts as one action.
Endpoint
POST https://api.pdfjs.express/watermark
Body params
The request body must be formatted as multipart/form-data
Name | Type | Description |
---|---|---|
file | Binary or URL | The file to add the watermark too |
license | string | Your PDF.js Express API license key. You must pass the correct license key depending if you are making the request from the server or the client. If no license key is provided, the output will be watermarked and usage will be heavily limited. |
text | string | The text to apply as the watermark. Defaults to 'PDF.js Express' |
color | string | The color the text should be. Should be a valid css color with no opacity. Defaults to 'cornflowerblue' |
position | 'center', 'top', or 'bottom' | Where to position the watermark. Defaults to 'center' |
scale | Number between 0 and 1 | The scale of the text compared to the document. Is ignored if 'fontSize' is set. |
fontSize | number | The size of the text that gets watermarked |
opacity | number between 0-1 | The opacity of the watermark. Defaults to 0.3 |
rotation | number | The rotation of the watermark in degrees. Defaults to 45 |
headers | stringified JSON | Headers to forward when the API downloads your file. Only used if file param is a URL. See this guide for more details. |
Response body (success)
A success response will come back in json
format and will contain the following:
Property | Type | Description |
---|---|---|
url | string | The URL where the processed file can be downloaded from (using proper authentication) |
id | string | The unique id of the file. Used to delete the file |
key | string | An authentication required used to GET the file. See details here |
Response body (error)
See the list of error responses for details.
Example
The following adds a watermark to the document when the user downloads it.
WebViewer({...options})
.then(instance => {
const { docViewer } = instance;
// a callback function to some "download" button
const onSave = async () => {
const fileData = await docViewer.getDocument().getFileData({});
const data = new FormData();
data.append('file', fileData);
data.append('license', my_license_key);
data.append('text', "Property of my app")
data.append('rotation', 0);
data.append('color', 'red');
// Process the file
const response = await fetch('https://api.pdfjs.express/watermark', {
method: 'post',
body: data
}).then(resp => resp.json());
const { url, key, id } = response;
// Download the file
const watermarkedFileBlob = await fetch(url, {
headers: {
Authorization: key
}
}).then(resp => resp.blob())
// Do something with blob...
// save(watermarkedFileBlob)
}
})
WebViewer({...options})
.then(instance => {
const { documentViewer } = instance.Core;
// a callback function to some "download" button
const onSave = async () => {
const fileData = await documentViewer.getDocument().getFileData({});
const data = new FormData();
data.append('file', fileData);
data.append('license', my_license_key);
data.append('text', "Property of my app")
data.append('rotation', 0);
data.append('color', 'red');
// Process the file
const response = await fetch('https://api.pdfjs.express/watermark', {
method: 'post',
body: data
}).then(resp => resp.json());
const { url, key, id } = response;
// Download the file
const watermarkedFileBlob = await fetch(url, {
headers: {
Authorization: key
}
}).then(resp => resp.blob())
// Do something with blob...
// save(watermarkedFileBlob)
}
})