Convert SharePoint documents to PDF using Microsoft Flow

convert.PNG

Edited Dec 10, 2018 to include “for a selected item” function in modern sites.

Can you convert SharePoint documents to PDF without leaving SharePoint? Heck, yeah!

Basically we’ll create this flow:

  1. “When a file is created or modified” in SP -OR- “For a selected item”
  2. Create document in OneDrive for Business -OR- OneDrive
  3. Convert document (OneDrive action in Flow)
  4. Create document in SP

It’s a bit of a hack but we get exactly the result often requested: convert SharePoint docs to PDF automatically. Here’s how to set this up. A video walkthrough using the “created/modified” trigger is available at the bottom of this post.

In Microsoft Flow, you can create your Flow with a “When a file is created or modified (properties only)” -OR- “For a selected item” trigger

For a selected item (modern experience only)

Save some time and import this .zip file to Flow

  1. Add trigger step “For a selected item”
  2. Add a “Get file properties” step and add “ID” from the dynamic content suggestion
  3. Add “Get file content” step and set File Identifier to “Identifier” from the suggested dynamic content
  4. Add a OneDrive for Business (ODB) or OneDrive step – create file
    Note: Use “Name” not “Title” and include file extension

  5. ODB – convert file
    convert2
  6. SharePoint – create file (this can be in a different site or site collection or the same from which it came)
    Note: add document extension (.pdf) after filename using “Name” from “Get file properties” step

  7. Save and test your flow!

When a file is created or modified (properties only)

Before you begin your Flow, create a sort of trigger field/column in your Document library. I’ll use a checkbox named “Publish”.
publish.PNG

Alternatively, you could just say whenever a file is added to a particular folder, Convert it upon creation/addition.

Now build a Flow as follows:

  1. Trigger: SharePoint – When a file is created or modified (properties only)
  2. If you’re using a column as a trigger, add a condition control where a conditional column like “Publish” equals true. If not using a condition skip to step #3.
    Note: You’ll need to edit this condition in advanced mode to remove the single quotes from around the word true for it to work correctly. See this post for help.
    condition

    Within the “if yes” section, continue these steps:
  3. Add a “Get file properties” step and add “ID” from the dynamic content suggestion
  4. Add “Get file content” step and set File Identifier to “Identifier” from the suggested dynamic content
  5. Add a OneDrive for Business (ODB) or OneDrive step – create file
    Note: Use “Name” not “Title” and include file extension

  6. ODB – convert file
    convert2
  7. SharePoint – create file (this can be in a different site or site collection or the same from which it came)
    Note: add document extension (.pdf) after filename using “Name” from “Get file properties” step

You may wish to add this additional step that unchecks the original trigger column so that another PDF isn’t created incidentally when the original document is edited:

  • SharePoint – update file properties –> set column to default/blank

Test your Flow!

Optional additional steps for either scenario

  • Add a step to go back and “Delete” the word doc created in OneDrive
  • SharePoint – update file properties (to copy any column data from original home to new home such as “meeting date”)

24 Replies to “Convert SharePoint documents to PDF using Microsoft Flow”

  1. Hello, thank You for good article, however I have problem with: Get file content. Error below. I checked everything and no idea what is wrong. Could You please be so nice to support ?
    {
    “message”: “SharePoint Site Address ‘Supply Chain Management – https://neapco.sharepoint.com/Europe/4_Manufacturing/SCM‘ is not valid\r\nclientRequestId: f7d6948d-507f-4afd-bbf7-53c4e1117bb0″,
    “fromPolicy”: true
    }

    1. The easiest way to do it is navigate to the news page you want to print, then Ctrl + P and save it to PDF!

  2. Thank you so much for this I donated last month when I put this in place and thrilled my client. 🙂

    One challenge I’ve come across, during the File Properties update, one of the properties in the “from” library is not available to select from the Dynamic Content pick list. Have you seen that before?

    1. Hi Colleen, and thanks so much for your support and kind note on the donor wall. I’m happy to help. Sometimes not all options show up in the dynamic content picker – try using the search box in dynamic content to confirm it’s not available. If still unavailable, may I ask what field it is and what column type (people, lookup, date, number, etc.) it is?

  3. What would be absolutely fabulous is a workflow that would not only convert the document to a PDF but OCR it at the same time before saving it. THAT would be life changing.

  4. Hello I have successfully used your guide “For a selected item”. Thank you for this helpful and useful tutorial. Unfortunately I am having just a tiny issue: My pdf’s end up having a .docx.pdf extension. Could you please give me some tips in order to fix the issue?
    thanks a million

      1. Thank you Nate, following your suggestions I found the issue. In the second task “Get file properties” section “Id”, in my configuration there was only “ID”, while when I imported your Zip in that section there was “entity.ID”. All the others task were the same. Thank you
        sergio

    1. Hi Amr, I needed to make some updates since this post was over a year old. I’ve modified the steps and tested. This should work now.

  5. Thanks for the post. However, I’m wondering if the pdf will have the same document-ID than the original doc file? In a regulated environment it is essential not to have the same document (as pdf & doc) with different IDs?

  6. Hi,
    I’m having an issue on the Convert pdf action. I have this BadGateway error. Do you have any idea on what’s causing this error?

    Thank you.

  7. Hey Nate – thanks so much for the video! Currently, it looks like the solution we require each user running the flow to have the same temporary “wf” folder in their personal one drive for business folder. This makes it a little hard to deploy across different users.

    Do you have any thoughts on deploying this without the folder as a requirement? Is there any way to use an o365 group to make it so that individual users don’t need the folder?

    I assume not, since the convert to PDF action requires One Drive for business. If that’s the case we may have to wait to see if the Convert Content action gets PDF support instead of just text

    1. One way to get around is to use a service account to run the flow. this way you will only create the interim folder in ODB once.

      Nate, thanks for putting this together mate.

Leave a Reply to Colleen ParkerCancel reply

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