How to Delete Pages from a Word Document using Node.js

Cloudmersive
2 min readDec 20, 2023

--

We can easily enhance our document management applications with minimal code using free API solutions.

Using the ready-to-run code examples provided further down the page, we can take advantage of a free API that removes a subset of pages from our DOCX files. We can format our request like the below example:

 {
"InputFileBytes": "string",
"InputFileUrl": "string",
"StartDeletePageNumber": 0,
"EndDeletePageNumber": 0
}

And our response will contain the encoding for our updated file with the specified pages removed.

To use this API for free, we’ll just need a free-tier API key to authorize our reqeusts. These allow a limit of 800 API calls per month — perfect for getting our new projects off the ground with no commitment.

To structure our API call, we can begin by installing the SDK. We can do that either by running this command:

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

Or, alternatively, by adding this snippet to our package.json:

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

With that out of the way, we can copy the below code into our file to call the function:

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


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

Now we can quickly & seamlessly remove entire sections of 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