How to Convert PDF to Word (DOCX) using JavaScript

Cloudmersive
2 min readAug 18, 2022

--

If you’re looking to make PDF to DOCX conversions at scale, look no further. Our PDF to DOCX conversion API makes this transition both simple and easy as a cloud service — you can structure your API call with zero hassle using the ready-to-run code examples provided below. You can use this API for free by registering a free account on our website (you’ll get a limit of 800 API calls per month with zero additional commitments).

You can structure your API call using the XHR request capability in JavaScript by copying the below code examples:

var data = new FormData();
data.append("inputFile", 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/pdf/to/docx");xhr.setRequestHeader("Apikey", "YOUR-API-KEY-HERE");xhr.send(data);

Alternatively, you can first install the jQuery library:

bower install jquery

And then call the API:

var form = new FormData();
form.append("inputFile", fileInput.files[0], "file");
var settings = {
"url": "https://api.cloudmersive.com/convert/pdf/to/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);
});

No further code required — you can start converting right away.

--

--

Cloudmersive

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