How to set the footer in a Word DOCX document in Python

Setting DOCX footers with Python actually turns out to be a rather mind-numbing task and one that can eat up most of your day. I can verify this as I just did this. But rather than drag you through the mud with me, I will give you the means to rise above it. My solution is now part of an API, which I will show you how to use.

First we need to import our API client via pip install.

pip install cloudmersive-convert-api-client

Next we will be calling edit_document_docx_set_footer from our created API instance. The details for this are as you see below.

from __future__ import print_functionimport timeimport cloudmersive_convert_api_clientfrom import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = cloudmersive_convert_api_client.Configuration()configuration.api_key['Apikey'] = 'YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['Apikey'] = 'Bearer'# create an instance of the API classapi_instance = cloudmersive_convert_api_client.EditDocumentApi(cloudmersive_convert_api_client.ApiClient(configuration))req_config = cloudmersive_convert_api_client.DocxSetFooterRequest() # DocxSetFooterRequest | Document input requesttry:# Set the footer in a Word DOCX documentapi_response = api_instance.edit_document_docx_set_footer(req_config)pprint(api_response)except ApiException as e:print("Exception when calling EditDocumentApi->edit_document_docx_set_footer: %s\n" % e)

OK, there you go! Easy as apple pie. This same API also allows you to edit DOCX files in a number of other ways, such as adding paragraphs, tables, and images.

Image for post
Image for post
No fancy coding needed today!

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