How to Convert PDF to Microsoft Word DOCX in Node.js
Content stored in PDF format can’t be easily accessed or edited. In DOCX format, you can apply themes, styles, and myriad additional formatting options to your newly converted PDF content. The below Node.js code will quickly convert your PDF documents into DOCX format with extremely high fidelity, ensuring you won’t have to waste time fixing dozens of conversion mistakes (i.e., those typically encountered when using run-of-the-mill online PDF to DOCX converters).
To begin SDK installation, run the below command:
npm install cloudmersive-convert-api-client --save
Or copy the below snippet to your package.json instead:
"dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}
With installation complete, include the remaining code examples (these are already formatted & ready to run on your console):
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.ConvertDocumentApi();
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.convertDocumentPdfToDocx(inputFile, callback);
To complete your API call, you’ll just need to authenticate the service with a free-tier Cloudmersive API key; you can get one by registering a free account on our website (free accounts supply a limit of 800 API calls per month with no commitments).