How to Add a Watermark to a PDF Document in Node.JS

Cloudmersive
2 min readNov 3, 2020

--

Because PDF documents are often used to share proprietary and sensitive information, it is important that you put measures in place so that the information is not used incorrectly and unadvised. As a solution to this, watermarks can be placed on your PDF documents for a variety of reasons: denoting draft documents, specifying security levels, and use of brand name to avoid misuse. This API will allow you to instantly add a watermark to your documents to solve this problem. The parameters for this function include the watermark text, font name, font size, font color, font transparency, and the input PDF file.

You can run this API by using this command to install the SDK:

npm install cloudmersive-convert-api-client --save

Or, you can add this snippet to your package.json:

"dependencies": {
"cloudmersive-convert-api-client": "^2.4.8"
}

Then, you can call the function:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveConvertApiClient.EditPdfApi();var watermarkText = "watermarkText_example"; // String | Watermark text to add to the PDF (required)var inputFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | Input file to perform the operation on.var opts = {
'fontName': "fontName_example", // String | Font Family Name for the watermark text; default is Times New Roman
'fontSize': 8.14, // Number | Font Size in points of the text; default is 150
'fontColor': "fontColor_example", // String | Font color in hexadecimal or HTML color name; default is Red
'fontTransparency': 8.14 // Number | Font transparency between 0.0 (completely transparent) to 1.0 (fully opaque); default is 0.5
};
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.editPdfWatermarkText(watermarkText, inputFile, opts, callback);

You can retrieve the API Key for this function at no cost and with no commitment on the Cloudmersive website. This will give you access to 800 monthly calls across our entire API library.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Responses (2)