How to Automatically Accept Track Changes in a DOCX File using Node.js
Accepting track changes in any DOCX file is as simple as flipping a switch. We can flip that switch without needing to open our document when we include a free API solution in our Node.js application.
Using the below code, we can take advantage of a free API that seamlessly interacts with our DOCX files and accepts any & all track changes within our documents. Thiis will keep track changes on after the operation is complete, but any pending changes in the document will be resolved. We can additionally engage an optional parameter that repairs our documents when they have errors (this is automatically turned on and can be turned off by customizing our request).
We can structure our API call in a few quick steps — starting with installing the SDK. We can either install by running the below command:
npm install cloudmersive-convert-api-client --save
Or by adding this snippet to our package.json:
"dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}
Lastly, we can copy the below code into our file and call the function. To authorize our requests, we’ll need a free-tier API key (these allow a limit of 800 API calls per month with no commitment):
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.editDocumentDocxAcceptAllTrackChanges(inputFile, callback);
Now we can easily improve our DOCX editing workflows with a simple and free-to-use solution.