How to Convert DOCX to JPG in Node.JS

Converting document files into images can be an incredibly useful feature to have, but it is not always easy to set up, especially for Node.JS users. In this particular case, we will be diving into conversion between Word DOCX files and JPG image format. To avoid this dragging out for the whole afternoon, we will be making good use of an API that was built exactly for this task.

Aforementioned API will be needing its library before we continue. We can install it using npm.

npm install cloudmersive-convert-api-client --save

And now we just need to use our DOCX file as an argument for convertDocumentDocxToJpg, the details for which are below:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.ConvertDocumentApi();var inputFile = "/path/to/file"; // File | Input file to perform the operation on.var opts = {'quality': 56 // Number | Optional; Set the JPEG quality level; lowest quality is 1 (highest compression), highest quality (lowest compression) is 100; recommended value is 75. Default value is 75.};var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.convertDocumentDocxToJpg(inputFile, opts, callback);


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