How to Delete Pages from a Word Document in Power Automate
Programmatic document adjustments can be real time-savers in the long run. Whether we’re adding, subtracting, or adjusting content in a document, Power Automate is the place to do it.
Word (DOCX) documents continue to see widespread use in businesses around the world; if we’re building flows to expedite file processing actions, there’s a good chance we’re dealing with DOCX files on a regular basis.
Delete pages from a Word document in Power Automate
In this article, we’ll learn a quick and easy way to trim a range of pages off a Word DOCX document in a Power Automate flow. To handle our document trimming action, we’ll take advantage of an API available via the Cloudmersive Document Conversion connector.
In this demo, we’ll build a manually triggered, instant cloud flow so we can have full control over our data when we eventually run our test.
To begin, we’ll use a Get file content action to retrieve a multi-page DOCX file from our system. In my example flow, I’ll be using the OneDrive for Business iteration of this action; if your file is located in a SharePoint folder, you’ll need to use that iteration instead.
Now that we’ve retrieved our example DOCX file, we’ll add a new action and search for Cloudmersive connectors.
We’re looking for the Cloudmersive Document Conversion connector, which has a green logo.
To view the full actions list, we’ll click on the “See more” link to the right of the connector name.
From there, we’ll search for an action titled Delete, remove pages from a Word DOCX document.
When we click on this action, Power Automate will prompt us to create our Document Conversion connection and authorize it with an API key.
To get a free API key, we can head to the Cloudmersive website and create a free account. This will allow us to make a limit of 800 API calls each month with zero commitments (our limit will reset at the beginning of each month).
To begin configuring our request, we’ll click “Show all” to view the advanced parameters.
First, we’ll satisfy the ReqConfig/InputFileBytes paramater with dynamic content from our Get file content action.
Next, we’ll enter the range of pages we’d like to delete from our DOCX file in the ReqConfig/StartDeletePageNumber and ReqConfig/EndDeletePageNumber parameters.
We’ll use a 1-based index to select the pages we’re deleting. This means the 1st page is page 1, the 2nd page is page 2, and so on (this stands in contrast to documents which use a 0-based page index).
In my example, I’m only interested in deleting the 2nd and 3rd page of my document, so I’ll be entering 2 and 3 into the StartDelete and EndDelete parameters respectively.
To wrap up our flow, we can either update our original DOCX file with the modified document results, or we can create an entirely new file in the same (or a different) folder.
In my example, I’ll use a Create file action and place the new, trimmed version of my document in the same folder as the original file.
Once we’re finished creating or updating our file, we’ll save our flow and run a quick test.
And that’s all there is to it! We’ll find our trimmed test document in the folder we selected.
Conclusion
Now that we understand how to use this action in a basic, instant cloud flow, we can easily expand its usage to automated flows dealing with a high volume of DOCX files at scale.
It’s a great tool to use when we’re trimming the same page range off multiple documents of the same type — like contracts or proposals, for example.