How to Remove Headers and Footers from a Word DOCX Document using Power Automate
Cleaning up MS Word (DOCX) files manually can be a real pain. Sometimes, it’s best to lean on simple, easy-to-use process automation tools to get the job done.
Removing the header and footer sections of a DOCX document is often necessary to enhance the compatibility of our file before we convert it (e.g., to PDF), and it’s also a useful step towards standardizing a set of files and optimizing them for some downstream file processing (e.g., text analysis).
In Power Automate, we can use the Cloudmersive Document Conversion connector to build flows (ranging greatly in complexity) that remove DOCX headers and footers programmatically, leaving us with a new & trimmed iteration of the original file.
Create an Instant cloud flow that removes DOCX headers and footers
In this article, we’ll walk through a brief example flow that uses the Remove headers and footers from Word DOCX document API to edit manually uploaded documents and store them in a separate SharePoint folder from the original.
Ask users to upload a DOCX file
In this example flow, we’ll quickly create a Manual trigger input which asks flow users to upload a DOCX file (with headers and footers to remove).
Find Cloudmersive connectors in Power Automate
Next, we’ll add a new action and search the Power Automate connector library for Cloudmersive connectors.
This will bring up a list of several different Cloudmersive connector options; we’re looking for the Document Conversion option with the green logo.
We’ll reach the full actions list by clicking “See more” to the right of the connector name.
From there, we’ll search for the Remove headers and footers from Word DOCX document action.
Create and authorize a Cloudmersive API connection
After we select this action, we’ll create our Document Conversion connection. Cloudmersive connectors us API keys for authorization; we can get a free API key (800 API calls/month) by creating a free account on the Cloudmersive website.
Configure parameters to remove DOCX headers and footers
We’ll now configure our Remove headers and footers request. To start, we’ll click “Show all” to view the Advanced parameters (in the case of this action, these are the only parameters available to configure).
Before we configure our request, let’s quickly review what each parameter is asking for.
- ReqConfig/InputFileBytes — takes the DOCX file byte string from our manual file input step
- ReqConfig/InputFileUrl — takes a file URL in place of a file byte string (not applicable in this example)
- ReqConfig/RemoveFooters — takes a Boolean (True or False = Yes or No in Power Automate) to determine if DOCX footers should be removed
- ReqConfig/RemoveFooters — takes a Boolean (True or False = Yes or No in Power Automate) to determine if DOCX headers should be removed
In this example, we’ll configure all these parameters except for the InputFileUrl parameter, and we’ll elect to remove both headers and footers.
The output from this action is a temporary file URL representing a cached version of our DOCX file on the Cloudmersive public cloud server. This temporary reference speeds up our flow if we make subsequent edits to the same document, but we won’t be chaining edits together in this case.
Wrap up the flow
At this point, we’ll add two final actions into our flow to finalize our automated process.
Download the temp URL to get modified DOCX file bytes
The first action will come from the Document Conversion connector once again. It’s called Finish editing document, and download result from document editing; this action converts the temporary URL output from the Remove headers and footers action to a file byte string.
We’ll simply pass the body/EditedDocumentUrl value to the ReqConfig/InputFileUrl field, and we’re all done configuring this action.
Create a new DOCX file
Our second finalization action will be a Create file action from the SharePoint connector.
We’ll use this action to create a new version of our DOCX file with headers and footers removed in a separate SharePoint folder from the original.
As shown in the above example, we can dynamically name our new DOCX file using the same name as the original input document (in this case, we’ve added the string “removed headers and footers__” to distinguish the output in our example).
Test the flow with a relevant DOCX file
At this point, we’ll save our flow, run a test, and upload a DOCX file with headers and footers.
In this example, the test document has the below header and footer:
When our flow finishes running, we’ll find our new document in the target SharePoint folder.
When we open this document, we should find that the header and footer sections are missing.
Conclusion
In this article, we learned one way to remove headers and footers from individual Word DOCX documents using the Cloudmersive Document Conversion connector in Power Automate.
While this example flow demonstrated a manually triggered use-case, we can just as easily incorporate this action into automated flows that edit our files before performing some additional processing (e.g., converting to a new format or analyzing text).
Don’t forget to check back in for more Power Automate walkthroughs on this blog!