How to Compare Two Word DOCX Documents using JavaScript

Whether you’re seeking to uncover near-duplicate text or simply check for updated versions of an important document, you shouldn’t have to waste your time comparing manually; there’s an API for that. Our DocX comparison API will automatically check for the differences between two input DocX files and highlight the differences for you. It’s simple and easy to use by structuring your API call with ready-to-run JavaScript code examples from our API console — and I’ve provided those below for your convenience. You can use this API for free by registering a free account on our website (with this account, you’ll receive a limit of 800 API calls per month).

We can structure our API call in two different ways to use this API — starting with a way that utilizes the XHR feature in JavaScript:

var data = new FormData();
data.append("inputFile1", fileInput.files[0], "file");
data.append("inputFile2", fileInput.files[0], "file");

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://api.cloudmersive.com/convert/compare/docx");xhr.setRequestHeader("Apikey", "YOUR-API-KEY-HERE");xhr.send(data);

Otherwise, you can easily utilize this API with jQuery; first install the library by running the below command:

bower install jquery

And then use the below code examples to structure your API call:

var form = new FormData();
form.append("inputFile1", fileInput.files[0], "file");
form.append("inputFile2", fileInput.files[0], "file");
var settings = {
"url": "https://api.cloudmersive.com/convert/compare/docx",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "multipart/form-data",
"Apikey": "YOUR-API-KEY-HERE"
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});

Nice and simple. You’re all set once you copy your API key into the relevant string within either code block.

--

--

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
Cloudmersive

Cloudmersive

437 Followers

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