How to split a single Word DOCX into Separate Documents by Page in Node.JS

Cloudmersive
2 min readMay 12, 2020

--

Having the option to separate DOCX pages into separate files can certainly be useful, but setting this up can really eat up your afternoon. I propose a different solution, one that will instead require but a few minutes. Let’s look at how it works.

We are going to use a Cloudmersive API client as our shortcut, which will require installation:

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

Our next step is to instantiate an API using a free key. Then proceed to use this instance for a splitDocumentDocx function call.

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.SplitDocumentApi();var inputFile = "/path/to/file"; // File | Input file to perform the operation on.var opts = {'returnDocumentContents': true // Boolean | Set to true to return the contents of each Worksheet directly, set to false to only return URLs to each resulting document.  Default is true.};var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.splitDocumentDocx(inputFile, opts, callback);

Easy! Your return will include all of the individual page files. Alternatively you can set returnDocumentContents to false, which will give you download URLs instead.

Why get a headache when an API can do it for you?

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet