Use Flow to PDF Convert Email Attachments to OneDrive, Dropbox, Google Drive, Etc.

As part of our ongoing series about using the Muhimbi PDF Converter REST-based API in combination with Microsoft Flow, Logic Apps and PowerApps, we present a cool example which converts all email attachments to PDF and archives them to a file service. (An example that converts the email body itself, can be found here)

For those not familiar with the product, the Muhimbi PDF Converter REST-based API is a popular product to PDF Convert, Merge, Watermark, Secure and OCR files from Microsoft Flow, Logic Apps, PowerApps as well as your own code using C#, Java, Python, JavaScript, PHP, Ruby and most other modern platforms. Leave a message below or contact us if you have any questions.

Update: Microsoft Flow / Power Automate now provides more control over emails, which makes life a lot easier, and generates higher fidelity output. Please read this new blog post if you are interested in email to PDF Conversion.

The examples in this series are becoming increasingly complex, so today we have to dig slightly deeper than before.

In this example we’ll show how to create a simple Flow that is triggered whenever an email – containing attachments – is received in Office 365 Outlook. The Flow then iterates over all attachments and converts the ones it knows how to convert to PDF. The resulting PDF files are archived to a OneDrive for Business folder, which will sync the files to other systems providing the sync client is installed somewhere.

Remember that this is just an example, it can easily be modified to use different email providers (, Gmail) and the converted attachments can be written to (or emailed) via any of the 100+ available Flow services, including Google Drive,, DropBox, OneDrive, SharePoint etc.

There are many reasons for building a workflow like this one. What we hear a lot from customers who do something similar, is that their regulatory body dictates that all files are made available, and discoverable, in a standardised format. PDF (specifically PDF/A which we support as an option) is often the format of choice.

From a high level, the Flow works as follows:

PDF Attachments - Overview

The full Flow can be found below. It is automatically created by the Flow Template named Archive email attachments in PDF format to OneDrive, it is just a matter of filling out the blanks, specifically:

  • Save to OneDrive – Folder path: Specify the path in OneDrive where the converted attachments will be written to.

There is something important to keep in mind for this particular template / example and that is that all files are written to a flat folder. If we use the original attachment file name to save the PDF in OneDrive then files would potentially be overwritten if a single email has multiple attachments with the same name (rare but possible) or multiple emails are processed and some use an attachment with the same name (more common).

To get around this we use the Compose action to convert the time that the workflow is executed, which matches the time the email is received, and clean it up for use in file names (replace ‘:’ with ‘-‘). We then concatenate it to each file name. If your requirements are different then feel free to change this or – for example – add this time stamp to the OneDrive path to automatically create a sub-folder for each email and their attachments.

PDF Attachments - Detail - Part1PDF Attachments - Detail - Part2

One of the tricks we use in this example is changing the default ‘Fail on error’ option in the Muhimbi Workflow actions from Yes to No. As a result, the Flow will not fail if an unsupported or broken attachment type is encountered. By evaluating the Result Code we can decide if the operation was successful and write the PDF to OneDrive. For more details about this concept see the Error handling section in our Core Concepts knowledge base article.

That’s it, now publish the Flow and send an email containing some Word, Excel, PowerPoint or other supported files types to the email address associated with the Flow. After a few moments PDFs will appear in the destination folder.

For more details about using Muhimbi’s Flow actions, see the Core Concepts knowledge base article as well as all other Flow related posts.

If you have any questions about extending this Flow / template, or implementing it in your environment, then please leave a message below or contact our friendly support desk. We are here to help.

Labels: Articles, EML, Flow, MSG, OneDrive, pdf, PowerApps, Workflow

Have a Question?
We’re Always Happy to Help.

© Muhimbi Ltd. 2008 - 2024
This website uses cookies to ensure you get the best experience. Learn more