How to Disable Track Changes & Revisions in a Word Document using Node.js
Thanks to the OpenXML document standard, building applications that interact with DOCX files is relatively easy. All we need is the right library — or the right API.
Using the ready-to-run Node.js code examples below, we can take advantage of a free API that disables track changes within a DOCX document and automatically accepts any pending changes. This makes it easy to programmatically finalize DOCX revisions and save the results in a custom application workflow.
To use this API for free, we’ll just need a free-tier API key, which will allow a limit of 800 API calls per month & no commitments. This is a great option for getting projects off the ground & scaling quickly.
We can begin structuring our API call by installing the SDK. To do that, we can either run this command:
npm install cloudmersive-convert-api-client --save
Or we can add this snippet to our package.json:
"dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}
Finally, we can use the below code to call the function. We can include our API key and our file in this snippet:
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.editDocumentDocxDisableTrackChanges(inputFile, callback);
Now we can easily finalize a document revision process in a custom applicaiton workflow.