PowerApps & Flow 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.

Check out my Advanced Flow Course

3.  Add a SharePoint action Get file content.  This is where you select the specific example file (template) from step 1.
sharepoint-flow-get-file-content

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.

flow-create-file-content

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.

update-file-sharepoint-customer

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.

get-file-content-new-file-sharepoint

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.

onedrive-flow-create-file

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.

onedrive-convert-file-pdf-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.

create-pdf-sharepoint-library

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?

image

10.  Then lastly, you will probably want to delete that temporary PDF over in OneDrive.  Add the OneDrive action to delete a file.

delete-file-onedrive

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.

powerapps-triggered-flow

Here’s an hour long video, where I go over all of this:

watch-power-hour-convert-pdf

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.

One comment

  • Hi Laura,

    I thought I had this working perfectly until I logged in as another user (the Flow uses a connector under a generic service account) – the Flow fails every time on the “Create File in OneDrive” action (Error below)

    InvalidTemplate. Unable to process template language expressions in action ‘Create_file_-_OneDrive’ inputs at line ‘1’ and column ‘2068’: ‘The template language expression ‘json(decodeBase64(triggerOutputs().headers[‘X-MS-APIM-Tokens’]))[‘$connections’][‘shared_onedriveforbusiness’][‘connectionId’]’ cannot be evaluated because property ‘shared_onedriveforbusiness’ doesn’t exist, available properties are ‘shared_sharepointonline, shared_office365’. Please see https://aka.ms/logicexpressions for usage details.’.

    When I log back in with the account creating it, it works every time. I am logged into OneDrive in the account (mine) when testing it.

    I am sure this is something simple, but I cannot find it.

    Thanks,

    Warren Belz
    Ventia Utility Services
    Rockhampton
    Australia

    Like

Leave a reply or question

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.