Power Apps & Power Automate Convert to PDF
Previously, I wrote a post called Microsoft Flow & Quick Parts, which shows how you can insert fields from SharePoint into your document via Flow and Quick Parts. Many times in business processes, this document needs to be output as a PDF file, in order to be archived or sent out to a customer.
Currently in Flow, the only free way to convert a file to a PDF, is using a OneDrive for Business action, so the file can’t just be in a SharePoint library, it has to be in OneDrive in order to convert it, then it can be put back in SharePoint. Here are the steps and associated video. You’ll notice in these screenshots, some small white text at the bottom. That’s what you see in Flow when you hover your mouse over the dynamic content, so that you can double check that it’s correct.
1. You need to have an example (template) file to start with. If you followed the steps in the post about Flow and Quick Parts, use a blank file that has all of the quick parts already inserted. This file can be anywhere, it can be in a library by itself if you’d like.
(If you’re coming from the SharePoint world where we’ve always done this with a custom content type, that method doesn’t currently work with Flow & modern SharePoint)
2. I’m not going to start with a Flow trigger here, there are many different ways you can start your Flow, such as when an item is first created, modified, or when someone manually triggers it. So… you already have a trigger, I’m going to start with the first action. I’ll just say, for example, that I have a SharePoint list of customers, and I’m going to select a customer and use the “for a selected item” trigger. Then I’ll have metadata about that customer that I can insert into the document, in the quick parts.
3. Add a SharePoint action Get file content. This is where you select the specific example file (template) from step 1.
4. Add a SharePoint action Create file. This address and folder path is where you have a library that has a bunch of columns with information about the customer. For the filename, I just gave it the ID of the customer, but you could add multiple fields and even a date here, if you want to make it more unique. The important part is for the File Content, pick the file content (dynamic content) from the previous action.
5. Add a SharePoint action Update file properties. This is the same library as in the previous action, and use the ItemId of the previous action (create file). I show an example here, of populating the customer name from the customer that I mentioned at step 2. I’m only showing one field, but you may have a bunch of them, this is where you fill them all in, so that the metadata of this new file in the library will have all of the pertinent metadata about this customer.
Theoretically, this is just a temporary file and ultimately needs to be a PDF anyway, so I’m not bothering with a bunch of dynamic lookup information from the SOW library to the customer list, since that makes quick parts much more complicated.
6. Add another SharePoint action Get file content. Rename it to Get file content new file. Use the ID of the file that you created in the create file action. You may notice that this is the second time we’re getting the content, this is because it’s a new file.
7. Add a OneDrive for Business action Create file. Rename it to Create file in OneDrive. For the path, it’s up to you. I just chose the root of my OneDrive. For the file name, I’m just using the Name from the create file action. The file content is important. This is where you use the file content from the previous action.
8. Add a OneDrive for Business action Convert file. Rename it to Convert file to PDF. For the ID, select the one from the previous action.
9. Okay now you have a PDF file, so where do you want to put it? Here’s how you can put it in SharePoint. Add the SharePoint action Create file. Rename it to Create PDF in library. Use the file name and content from the previous action.
Here’s an example of what it could look like if you wanted this Flow to also send that attachment in an email, maybe send it to your customer?
10. Then lastly, you will probably want to delete that temporary PDF over in OneDrive. Add the OneDrive action to delete a file.
Now try it out!
Next, you may be wondering about the title of this article, and wonder where PowerApps comes in. PowerApps can be used as a trigger (the very first step) if you’d like to click a button from within an app, to generate a PDF. So, your trigger would be different, you’d use the PowerApps trigger, send the ID of the customer over to the Flow (in my example, since it’s a list of customers). Then the Flow needs the get item action (renamed to “get customer”) to go get the additional metadata about that particular customer.
Here’s an hour long video, where I go over all of this:
If you’d like to see a full presentation that I did for Collab 365 virtual summit all about how to do the PowerApps triggering a Flow part, go here, and my session is called Using Microsoft Flow with PowerApps. And of course, I teach my own 8 hour advanced Flow course.