How to Convert SharePoint List Attachments to PDF in Power Automate
Asking users to upload files to any SharePoint list can easily result in a bunch of completely different file formats. Uploading a job candidate’s resume, for example, can mean we get a Word (DOCX) file, some image file (e.g., JPG), or a PDF, and asking for a report or schedule document can yield anything from Excel to PowerPoint or even CAD depending on the user’s preferences.
Converting list attachments to PDF ensures we end up with a standardized version of every file our users upload. Instead of asking users to ONLY upload their documents as PDFs, we can simply take matters into our own hands & automate PDF file conversions ourselves.
Thankfully, it’s really easy to do that in Power Automate. We can simply use a Cloudmersive Document Conversion connector action that autodetects input file formats & converts them to PDF, and then we can attach the result of that conversion back to the original list item.
Convert SharePoint List Attachments to PDF in Power Automate
We’ll now walk through a quick example flow to see this in action. In my example, I’ll be working off SharePoint’s template “Recruitment tracker” list, which has a built-in column for file (resume) attachments.
To begin, we’ll select the option to create an Automated cloud flow in Power Automate that starts with the SharePoint When an item is created trigger (this triggers flows when items are added to a specific SharePoint list).
Our first order of business is to configure our trigger action. To do that, we’ll open this action, select the Site Address our list lives on, and then select the List Name.
Next, we’ll add two additional SharePoint connector actions into our flow.
The first of these will be the Get attachments action. This action uses the list item ID from our trigger step to get information about file attached to each item, including the File identifiers, which we’ll need in file-content related operations.
The second of these will be the Get attachment content action. This action utilizes the File identifier value from the Get attachments step to retrieve file bytes from list attachments.
We’ll notice that Power Automate wrapped the Get attachment content action in a For each control by default. That’s because any given list item may contain an array of multiple attachments.
Within the For each control, we’ll quickly add a Condition before the Get attachment content action. We’ll use this condition to screen out PDF attachments before we get to our eventual PDF conversion step (we don’t want to waste resources attempting to convert PDFs to PDF). We’ll ask our flow to pivot when attachment DisplayName values contain the string ‘.pdf’.
We’ll then click & drag the Get attachment content action into the False branch of our condition. This means we’ll only get file bytes for attachments without PDF extensions.
Now we’ll incorporate our PDF conversion action.
To find it, we’ll add a new action and search for Cloudmersive connectors. We’ll locate the Cloudmersive Document Conversion connector, and once we find it, we’ll click “See more” to view the actions list.
We’ll now CTRL+F search for an action titled Convert Document to PDF, and we’ll select that action once we find it.
If it’s our first time using this connector, we’ll need to create our connection before we reach the parameters window we see in my example. To create our connection, we’ll need a free Cloudmersive API key, and we can get one by creating a free account on the Cloudmersive website (this allows a limit of 800 API calls/month with zero commitment). As we can see, my connection is named Document Conversion; I’m using a free API key in this demonstration as well.
We’ll now satisfy our request parameters with Attachment Content & DisplayName values from our earlier SharePoint connector actions.
At this point, we’ve asked our flow to retrieve attachments from new list items & convert all non-PDF files to PDF format. This conversion action supports a huge range of different files, so it’s unlikely we’ll encounter a file it can’t convert — but if that does happen, that particular flow run will fail and we won’t encounter any serious errors.
We’ll now wrap up our flow by attaching our converted PDF back to the original list item. This PDF will display alongside the original file attachment as a secondary PDF version, accessible to all list users.
We’ll use the Add attachment action to handle this part of our flow, and we’ll use OutputContent from our Convert Document to PDF action to satisfy the File Content field.
To name our file, we’ll reuse the original DisplayName value in this example, and we’ll add a PDF extension to the end of that string. This will result in a file that appears to have two extensions, which some folks may not like as it sometimes appears like a security risk; if we feel uncomfortable doing that, we can name the file however else we’d like.
At this point, we’re ready to save and test our flow. Since we created an automated flow, we’ll need to test by performing the flow trigger action (attaching a file to our SharePoint list).
In my example, I’m attaching two files to my test list item — one of which is a Word document, and the other of which is a PDF.
When our flow finishes running, we’ll find a version of our Word document attachment converted to PDF on our original list item.
If we take a look at my example flow run, we’ll notice that the first For each instance ran smoothly, and the second For each instance skipped all actions entirely. That means the PDF document was successfully screened out of the flow once the .pdf extension was identified by the Condition.
And that’s all there is to it!
Now we can easily create & upload a PDF version of any SharePoint list attachment with a seamless automated flow.