How to Get the Images from a Word Document in Node.js

Cloudmersive
2 min readNov 30, 2023

--

Images in DOCX documents are easily retrievable objects thanks to OpenXML formatting. With the right API or library, we can easily access image content and parse it into other files.

Using the ready-to-run code examples provided below, we can take advantage of a free API designed to extract all the images stored in a DOCX document and return them in a simple response object. Each object will contain information including the image encoding, path, ID, description, height & width, and more.

We can begin structuring our API call by installing the SDK. To do so, we can either run this command:

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

Or add this snippet to our package.json:

  "dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}

With installation out of the way, we can include the below code in our file to make our request. To authorize our request, we’ll need a free-tier API key (this will allow a limit of 800 API calls per month with zero commitments):

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 reqConfig = new CloudmersiveConvertApiClient.GetDocxImagesRequest(); // GetDocxImagesRequest | Document input request


var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.editDocumentDocxGetImages(reqConfig, callback);

Now we can easily access & distribute images in our DOCX documents without any manual intervention.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet