How to Delete Pages from a Word Document in Node.JS

Working with documents online is easier that you’d think, especially with the correct tools at your disposal. After using the Begin Editing function posted previously on this page, you can easily edit any document according to your needs. This API will allow you to delete one or a range of pages from a Word document in Node.JS. To use the function, you will need to input you file or file URL and specify the page range for deletion.

Image for post
Image for post

Start the function by running the following command to install the SDK:

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

Or, you can add this snippet to your package.json:

"dependencies": {
"cloudmersive-convert-api-client": "^2.4.8"

Then, you can 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 requestvar callback = function(error, data, response) {
if (error) {
} else {
console.log('API called successfully. Returned data: ' + data);
apiInstance.editDocumentDocxDeletePages(reqConfig, callback);

Make sure to run the Finish Editing function (tutorial previously posted) after you have finished your edits to complete the operation.

You can retrieve the API Key for this function at no cost and with no commitment on the Cloudmersive website. This will give you access to 800 monthly calls across our entire API library.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store