Advertisements

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”)
Advertisements

14 Comments

  1. Joshua Brown

    Reply

    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

    • Reply

      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.

  2. Pingback: Getting started wtih Microsoft Flow | Microsoft Home

  3. Angel

    Reply

    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.

  4. OOPE

    Reply

    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?

    • SharePoint Librarian

      Reply

      Unfortunately, this will cause the item to have a different Doc-ID.

Leave a Reply

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

%d bloggers like this: