How to Set Header and Footer Text in a Word DOCX Document using Power Automate

Cloudmersive
7 min readJan 30, 2025

--

Programmatically setting DOCX headers and footers might sound like something that requires a bunch of code — but that’s not the case when we use Power Automate to get the job done.

In Power Automate, we can leverage two Cloudmersive Document Conversion connector actions in a no-code, drag-and-drop flow to set text content in the header and footer sections of a Word document.

We can introduce entirely new text to our DOCX file, or we can parse text dynamically from upstream flow actions (e.g., copy text from within another document, or from some other text source).

Test with an Instant cloud flow

We can test this easily by setting up an Instant cloud flow with a series of manual user inputs.

In this case, our manual inputs will be 1) a file input field asking for a DOCX document and 2) a pair of text fields capturing header and footer text strings.

Find Cloudmersive connectors

To find the Cloudmersive Document Conversion connector action we need, we’ll first search for Cloudmersive connectors in the Power Automate connector library.

We’ll click “See more” to view the full actions list, and we’ll see a long list of actions available.

Search for relevant connector actions

The easiest way to find the actions we need is by CTRL+F searching through our browser. The first action we’re looking for is called Set the header in a Word DOCX document (we’ll notice the Set the footer action is located directly above that).

Create a Cloudmersive Document Conversion connection

When we select our first action, we’ll need to create our Cloudmersive Document Conversion connection. We can do that by adding a name for our connection (e.g., “Document Conversion”) and then providing a free Cloudmersive API key to authorize our request.

We can get a free Cloudmersive API key by visiting the Cloudmersive website and creating a free account (this allows up to 800 API calls/month with no commitments; it’s the same API key/account type we’re using in this walkthrough).

Set & customize the document header

We’ll now configure our Set the header request. We’ll start by clicking “Show all” to enumerate this action’s Advanced parameters.

Let’s break down what we’re looking at here.

We have a series of complex looking parameters intended to help fully customize the header section of our DOCX file. Many of these fields are intended to capture complex dynamic entries from upstream flow actions, and we won’t need them for a basic request.

We’ll start by passing file bytes from our manual trigger to the ReqConfig/InputFileBytes parameter. This specifies the document we’re adding a header to.

Next, we’ll click Add new item in the ReqConfig/HeaderToApply/Paragraphs section.

We’ll ignore the three input fields in this section (they’re not relevant without dynamic entries parsed from other documents), and we’ll then click Add new item again in the Contentruns section.

In the above section, we can begin customizing how our text will appear in the document header.

In this example, we’ll select the option to make our content Bold, and we’ll set Calibri as the Fontfamily. We’ll set our Fontsize to double the value we actually want (e.g., 60 = 30), and we’ll leave the rest blank (feel free to play around with these as much as you want in your own flow).

Finally, in the Textitems section, we’ll click Add new item once again, and we’ll find three inputs dedicated to setting the text run in our header.

We can add multiple text sections here, and we can set the 0-based index of each. We can also include the path value dynamically from other document’s we’ve pulled content from.

In this example, we’ll only worry about the Textcontent field. In here, we’ll pass the manual text input value we created in our Manual trigger step.

We’ve now finished configuring the text content in our header.

If we want our document to begin showing headers on any page other than the first, we can navigate down to the ReqConfig/HeaderToApply/SectionsWithHeader section of our request and set a Startingpagenumbers item.

We will be leaving this blank in our walkthrough.

Set & customize the document footer

Now that we’ve finished configuring our Set the header request, we’ll navigate back to the Cloudmersive Document Conversion connector actions list and select the Set the footer action. Our Document Conversion connection will be saved this time — we won’t need to provide a name or API key again.

As we can see in the above screenshot, this request is structured identically to the Set the headers request.

We’ll configure this request exactly the same way as before — only we’ll pass a URL from our Set the headers action to the Set the footers action instead of using the DOCX file bytes again.

So, why use a URL for this second action?

The answer is efficiency: Cloudmersive securely caches file content on the endpoint server for Document Conversion actions it expects us to chain together (i.e., make a series of unique API edits to a single document). Rather than constantly pass file bytes to and from the endpoint server, Cloudmersive returns a secure temporary URL to reference the in-progress modified version of our file. We’ll download the completed file at the end of the editing process.

Altogether, our Set the footer request should look something like this:

Now that we’ve chained our edits together, we’ll download the result from our secure temporary URL.

Download file bytes from the secure temporary URL

To do that, we’ll use one final action from the Cloudmersive Document Conversion connector called Finish editing document, and download result from document editing.

This action only has one parameter — ReqConfig/InputFileUrl — and we’ll pass it the URL from our Set a footer action.

We now have our modified DOCX file bytes, and we can write those to a new DOCX file using a Create file action. In this example, we’ll save our modified document in a SharePoint folder, and we’ll reuse the input file name (with an additional string) to name our file.

Run a manual flow test

We’ll now save our flow and test it.

To run our test, we’ll select a DOCX file from our system and enter header and footer text in our manual input fields.

When our flow finishes running, we’ll find the modified version of our document in our SharePoint folder.

And that’s all there is to it!

Conclusion

In this article, we learned how to set both the header and footer sections of a MS Word DOCX file using Cloudmersive connectors in Power Automate. We learned how to chain these actions together at high-speed using a secure temporary URL reference provided by the Cloudmersive endpoint server.

Don’t forget to follow this account for more Power Automate walkthroughs in the future!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet