How to Enable Track Changes & Revisions in a Word Document using Node.js
Streamlining DOCX editing processes is easy when we include the right APIs in our file processing applications.
Using the below code, we can take advantage of a free API that allows us to programmatically switch on track changes in our DOCX files within our Node.js application workflow. This allows us to easily automate the process of initiating document edits and save time manually interacting with dozens of shared files.
Before we begin structuring our API call, we’ll just need a free-tier API key to authorize our requests. A free-tier API key will allow us to make up to 800 API calls per month with no additional commitments (that total will reset the following month).
We can begin by installing the SDK. We can either run the below command:
npm install cloudmersive-convert-api-client --save
Or, alternatively, we can add this snippet to our package.json:
"dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}
Finally, we can copy the below code into our file to structure our request (with our API key and DOCX file included):
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.EditDocumentApi();
var inputFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | Input file to perform the operation on.
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.editDocumentDocxEnableTrackChanges(inputFile, callback);
That’s all there is to it — no more code required!