How to Update a PDF with Email Attachment Content in Power Automate
We can build all kinds of useful automated workflows to deal with email attachments in Power Automate. That includes merging PDF attachments from specific inbound emails to an existing PDF in our system.
We could, for example, target emails from a specific sender, check those emails for PDF attachments with certain names, and merge ONLY those specific documents with an existing PDF in our system.
There are limitations to this, of course; for instance, we’ll find it difficult to merge multiple attachments at once. Short of that, however, we’ll save a considerable amount of time assembling routine multipage PDFs via email.
Updating PDFs with PDF Attachment Content in Power Automate
The Office 365 Outlook connector in Power Automate provides an automated flow trigger action which returns attachment content & attachment names (along with tons of other useful information) to our flow. We can use a Condition control to screen the attachment names for ONLY documents with PDF extensions, and we can further screen for PDFs with specific content in their names. We can then use the SharePoint connector to retrieve the existing PDF we’d like to update from our team site, and finally, we can use the Cloudmersive Document Conversion connector to merge the PDF attachment with the existing document.
Let’s walk through an example flow that performs all these steps.
We’ll start by creating an Automated cloud flow that uses the When a new email arrives (V3) action from the Office 365 Outlook connector.
We’ll configure this trigger action to look for emails from a specific sender, and we’ll ensure our flow only triggers when those emails have attachments.
Right after that, we’ll insert a Condition control as our first post-trigger action.
We’ll ask our Condition to check the attachment name values from our trigger step for “PDF” and, in this demo case, “LOREM IPSUM”. We’ll use the toUpper() function to normalize the attachment name value to all upper case letters (this simplifies searching for content in our name string).
In the True branch of our Condition, we’ll use a Get file content action from the SharePoint connector to pull the existing iteration of our PDF from our team site.
Next, we’ll incorporate the Merge Two PDF action from the Cloudmersive Document Conversion connector.
We’ll find the Document Conversion connector by searching “Cloudmersive” in the Power Automate connector library & looking for the option with the green logo.
We’ll click “See more” to view the full actions list, and we’ll search for the action titled Merge Two PDF Files Together.
We’ll select this action, and then we’ll create our connection. To do that, we’ll need a free Cloudmersive API key, which we can get by creating a free account on the Cloudmersive website (free API keys permit up to 800 API calls each month with no commitments).
After we’ve saved our connection, we’ll configure two sets of identical parameters in our Merge Two PDF action. Both ask for input file bytes and file names.
We’ll pass the PDF bytes & file name from our SharePoint team site document in the first two parameters, and we’ll pass the PDF bytes and file name from the email attachment in the second two parameters. This ensures the new email attachment PDF will show up after the existing PDF content when we update the file.
Finally, to update our file, we’ll use the Update file action from the SharePoint connector. We’ll select the same file we picked in our earlier Get file content action, and we’ll use OutputContent from our Merge Two PDF action to update the existing file bytes.
We’ll now save our flow and test it by emailing ourselves a PDF document.
In this example flow, we’ll email ourselves a PDF containing one page of a Lorem Ipsum “contract document”.
When our flow finishes running, we’ll notice our For each control ran once for every attachment in our email. Even though we only attached one PDF in our example, Power Automate picked up on other attachments we may not have considered — like PNG icons in our email signature, for example. This is one reason why it’s important to screen for PDF attachments with our Condition control.
And that’s all there is to it!
We’ll find the updated version of our PDF on our SharePoint site. From now on, any time we receive PDF attachments with the specific name string we want from this specific sender, those attachments will merge with our continuously updated PDF.
Conclusion
In this article, we learned how to merge PDF email attachments from an inbound email with an existing PDF document on our SharePoint team site. We leveraged Cloudmersive, SharePoint, and Office 365 Outlook connector actions in this process.
Don’t forget to follow our blog if you’re looking for new ways to automate file-processing workflows & save time!