How to Get Styles from a Word Document using Node.js

Cloudmersive
2 min readNov 30, 2023

--

Maintaining consistent content delivery is easy when we can quickly extract relevant style data from example DOCX documents.

Using the ready-to-run code below, we can easily retrieve style data from a DOCX file in a simple response object. We’ll get the document style ID, information on bolds, italics, and underlines, and details about the font size and font family. With a free-tier API key to authorize our requests, we can perform this operation up to 800 times per month with no commitment.

We can begin structuring our API call by installing the SDK. Let’s either run the following command:

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

Or add the following snippet to our package.json:

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

Lastly, we can add the below code into our file to make our GET request:

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.GetDocxStylesRequest(); // GetDocxStylesRequest | Document input request


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

That’s all there is to it — no more code required!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

Responses (1)