How to add a page number to the footer in a Word DOCX document in Node.JS

While it initially seems simple, the process of using Node.JS to add page numbers into DOCX footers is actually quite an irksome one. What do you say we look at an easy shortcut instead?

In our package.json file, we can add this reference to our API client for easy installation.

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

Now we may construct our function call, which will use an instance of the API created using an API key. Here is what that looks like:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.EditDocumentApi();var reqConfig = new CloudmersiveConvertApiClient.DocxSetFooterAddPageNumberRequest(); // DocxSetFooterAddPageNumberRequest | Document input requestvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.editDocumentDocxSetFooterAddPageNumber(reqConfig, callback);

And that’s really about it. Once you submit your request, the API will handle the rest. If you enjoyed this easy method, you should peruse the rest of this library, as it contains many other great functions designed to save you time. For example you can convert between different document types, validate documents, and merge files, all with this same type of simple API call.

Image for post
Image for post

Written by

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store