How to delete any object in a Word DOCX document in Node.JS
For today’s example, our goal is to delete a specific object from a DOCX file, such as an image, table, or paragraph. Using an API, this task will be greatly simplified, allowing us to finish almost instantly, as you will soon see.
With this dependency reference for package.json, we will be able to add our API client to the project.
"dependencies": {
"cloudmersive-convert-api-client": "^2.1.6"
}
Our function call for editDocumentDocxRemoveObject will come next, which makes use of a newly instantiated API class object. If you look at the following example, you will see exactly what I mean.
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.EditDocumentApi();var reqConfig = new CloudmersiveConvertApiClient.DocxRemoveObjectRequest(); // DocxRemoveObjectRequest | Document input requestvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.editDocumentDocxRemoveObject(reqConfig, callback);
And that’s done! Our output will include a URL, which can be used to call the Finish Editing API to give you the edited document. To get lists of your available objects in the DOCX, you can use Get Tables, Get Images, and Get Get Body.