How to Remove an Object from an Online Word Document in Python

Cloudmersive
2 min readJan 29, 2021

--

Editing a document online can be a complicated process without the right tools — that’s why we have a variety of APIs to assist you in your editing process. Our remove object function can be used to delete any object, such as a paragraph, table, or image, from a Word document.

To leverage this helpful tool in Python, we will first need the path of the object; if you need to obtain the path, you can call other functions with our Get-Tables, Get-Images, or Get-Body APIs to assist.

Let’s begin by installing the SDK:

pip install cloudmersive-convert-api-client

Then, we can call the remove object function with the following code:

from __future__ import print_function
import time
import cloudmersive_convert_api_client
from cloudmersive_convert_api_client.rest import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_convert_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = cloudmersive_convert_api_client.EditDocumentApi(cloudmersive_convert_api_client.ApiClient(configuration))
req_config = cloudmersive_convert_api_client.RemoveDocxPagesRequest() # RemoveDocxPagesRequest | Document input request
try:
# Delete, remove pages from a Word DOCX document
api_response = api_instance.edit_document_docx_delete_pages(req_config)
pprint(api_response)
except ApiException as e:
print("Exception when calling EditDocumentApi->edit_document_docx_delete_pages: %s\n" % e)

In no time at all, the target object will be removed from your Word document. At this point, if you have finished modifying your document, you can run our Finish Editing API to tie everything together and download the document. Retrieve your personal API key on the Cloudmersive website by creating a free account; this will also give you access to 800 calls/month

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet