Skip to content
Browse Power Automate tutorials

Converting a document to PDF by hand is easy to forget. This walkthrough builds a flow that does it for a selected file, then adds a button to the library so that people do not have to look through the library’s menus for the flow.

Before you begin

You need:

  • A SharePoint document library with a Word file to test with. The example library is named Demo.
  • A second library to use as a working area. The example uses Template Processing. Each run makes its own folder there.
  • Permission to create flows, and to add and format columns in the library.
  • Premium licensing. Word Online (Business) is a premium connector. This flow starts from the library, so it runs under the license of whoever starts it. Each of those people needs a Power Automate Premium license, unless the flow itself is assigned a Process license, which covers everyone who runs it. See Licensing. If that does not fit your organization, see the article on generating PDFs with standard connectors.

The site, list, library and flow names in the screenshots are examples. Use your own.

Decide how repeat conversions should behave

Answer this before you build, because it changes the flow.

What you wantHow to build it
One PDF that is always currentCreate the PDF in a working folder, then move it with Replace. This article uses this approach
A new copy each timeAdd the run’s name to the PDF’s file name. In step 4, set File Name to Name, then -, then the run-name expression, then .pdf. No other run has the same name, so no copy replaces another. You can add the date and time as well, to make the names easier to read, but on its own a time can repeat. The copies stay until someone deletes them, so plan how long to keep them
Simple, and repeat runs do not matterCreate the PDF directly in the library. A second run for the same file is likely to fail

The PDF takes its name from the Word file, so “always current” holds only while that name stays the same. If someone renames the Word file, the next run makes a new PDF, and the old one stays. Two Word files with the same name in different folders also share one PDF in the destination, and each run replaces the other’s. If either matters, keep a separate destination folder for each source folder, and delete old PDFs after a rename.

1. Create the flow

Build the flow in your default environment. The library’s flow menu lists only flows from the default environment for this trigger.

  1. In Power Automate, select the default environment, and create an instant cloud flow.
  2. Name it, for example Convert Word Document to PDF - Document Library.
  3. Add the SharePoint trigger For a selected file, and select your site and library.

Use For a selected file for a library. For a selected item is for lists.

2. Get the file details

The trigger gives you the file’s ID, but the Word action needs its name.

  1. Add the SharePoint action Get file properties.
  2. Select your site and library.
  3. Set Id to the ID from the trigger.
  4. Save the flow. Saving as you go protects your work.

3. Convert the file

The action does not support files with a Confidential or Highly Confidential sensitivity label. Convert those files another way.

  1. Add the Word Online (Business) action Convert Word Document to PDF.

  2. In Location, select your SharePoint site.

  3. In Document Library, select your library.

  4. In File, type /. A small menu opens; press Esc to close it, so that the slash stays. Then add this expression after the slash:

    join(skip(split(body('Get_file_properties')?['{FullPath}'], '/'), 1), '/')

    The name in body() is the action’s name with underscores in place of spaces. If you renamed Get file properties, change it here.

Convert Word Document to PDF action with a slash and the join expression in the File box

The File box expects the file’s path inside the library, not an ID. Full Path from Get file properties starts with the library’s folder, as in Demo/Sub/Cloud Migration.docx. The expression drops that first part, so the box gets /Sub/Cloud Migration.docx, wherever the file is. If you use only / and File name with extension, a file in a subfolder isn’t found, or, when a file with the same name is at the top of the library, that file is converted instead.

4. Create the PDF

Each run creates its PDF in a folder of its own, so two runs never share a working file.

  1. Add the SharePoint action Create new folder. Select your site, set List or Library to your working library, and set Folder Path to Runs/ followed by this expression:

    workflow()?['run']?['name']

    workflow() returns details of the current run, including the run’s name, which is different for every run.

  2. Add the SharePoint action Create file.

  3. Select your site.

  4. In Folder Path, enter the run folder: your working library, then /Runs/, then the same expression. In the example, that is /Template Processing/Runs/ followed by the expression.

  5. In File Name, select Name from Get file properties, then type .pdf. Name does not include the extension.

  6. In File Content, select the PDF output from Convert Word Document to PDF. It’s listed as PDF document.

Create file action with Folder Path set to the run folder, the Name token followed by .pdf, and the converted PDF as File Content

If you chose the simple option, skip Create new folder, and set Folder Path to the final folder. You can then stop here and test.

5. Move the PDF and replace older copies

  1. Add the SharePoint action Move file.
  2. In File to Move, select the Id from Create file. The token appears as body/Id.
  3. Select the destination site and folder.
  4. Set If another file is already there to Replace.

Move file action with Fail this action, Move with a new name, and Replace options

The move leaves the run’s folder empty, and it stays in Runs. If a run fails, its folder keeps the working file, so you can see how far it got. The folder is named with the run’s name, which workflow() returns, so you can match it to the run in the run history.

Delete old run folders by hand. From time to time, open Runs in your working library and delete old folders. Before you delete one, make sure no run is in progress, and that the PDF is in the destination folder and opens correctly. Keep a failed run’s folder until you’ve found out why it failed. Delete only folders inside Runs, never Runs itself or the destination folder.

Convert one file at a time. The flow is meant for one conversion of a file at a time, whether it’s started from the button or the library’s flow menu, and whoever starts it. Nothing in the flow enforces that. Separate run folders keep two runs from sharing a working file, but both replace the same PDF. The PDF shows the run whose Move file replaced it last. If the Word file changed between two overlapping runs, that can be the run that started first, so the PDF can show the older version. If a run fails, the PDF from an earlier run stays as it was. To be sure the PDF matches the current Word file, wait until no other run for the file is in progress, then run the flow once more. If that run succeeds, the PDF comes from it.

6. Test from the library

  1. In the library, select a Word file.
  2. Select Integrate > Flows, and select your flow. With a file selected, Integrate can be under … on the command bar. The first time, select Continue. Then select Run flow.
  3. Wait for the PDF to appear, and refresh the library if it doesn’t show.
  4. Open the PDF and check it.
  5. Run the flow again for the same file. The time on the PDF should update, which shows that it was replaced.
  6. In Runs, the run’s folder is still there, and empty.

7. Add a column for the button

  1. In the library, select Add column, choose Text, and select Next.
  2. Enter a name with no spaces, such as ConvertPDF, and select Save. This keeps the internal name simple.
  3. Rename the column Convert to PDF.

8. Format the column as a button

  1. Select the column heading, then Column settings > Format this column.
  2. If the pane doesn’t show a box of JSON, select Advanced mode.
  3. Delete any text in the box, then paste the contents of flow-button-column.json from flow-button-column.zip. The JSON is adapted from the executeFlow sample in Microsoft’s PnP List Formatting repository, which is MIT licensed, so the download includes its license in LICENSE.txt.

Column menu with Column settings for Convert to PDF

The file contains a placeholder. Replace YOUR-FLOW-ID with your flow’s ID.

To find the ID, open the flow in Power Automate and select Export > Get flow identifier. You can also copy it from the flow’s address in the browser, where it is the value after /flows/.

Format column pane in advanced mode with the button JSON and the flow's ID in actionParams

These values can also be changed:

Part of the JSONWhat it controls
headerTextThe title of the panel that opens
runFlowButtonTextThe button in that panel
titleThe text that appears when you hover over the button

9. Test the button

  1. Select Save. The column shows a Power Automate icon on each row.

    Library row with a Power Automate icon in the Convert to PDF column

  2. Select the icon on a Word file.

  3. If the panel shows a run button, select it. Solution-aware flows wait for you to select Run flow, while other flows start after the panel appears.

  4. Confirm that the PDF updates.

To run more than one flow from a library, add another column with its own flow ID.

Share it with your team

Other people need access to the flow:

  1. On the flow’s details page, add them under Manage run-only users.
  2. Choose which connection the flow uses for those people.

People must have Edit permissions on the list or library to run the flow, and the licensing described above applies to each person who runs it.

Troubleshooting

SymptomLikely causeWhat to do
Convert Word Document to PDF cannot find the fileThe File box has an ID, or lacks the leading slash or the folderUse / and the Full Path expression from step 3
The PDF shows another file with the same nameFile has only File name with extension, so a file in a subfolder is read from the top of the libraryUse the Full Path expression from step 3
The second run failsThe PDF already exists in the destinationUse a run folder with Move file and Replace, or add the run’s name to the file name
Create file failsFolder Path doesn’t match the folder that Create new folder madeUse /Runs/ and the same run-name expression in both
Empty folders build up in RunsEach run leaves its folder behindDelete old folders by hand, as described in step 5
An old PDF stays after a renameThe PDF is named after the Word fileDelete the old PDF
A name with the date and time still failsTwo runs got the same timeAdd the run’s name to the file name, as in the table at the start
The flow is not under Integrate > FlowsIt is not in the default environment, it uses the wrong trigger, or it’s turned offUse For a selected file in the default environment, and turn the flow on
The button does nothing, or reports an errorThe flow ID is wrongPaste the ID again without the quotes or surrounding text
Someone cannot run the flowRun-only access, list permission, or license is missingCheck each item under Share it with your team
A step after Create file cannot find the new file, although the path is rightThe file is not available yetMicrosoft recommends a short delay, about a minute, before later actions use a file created from the Word connector. Add a Delay before the step that fails
The conversion fails for a labeled fileThe file has a Confidential or Highly Confidential sensitivity labelHandle these files outside the flow
The button fails on a PDFThe file is not a Word documentSelect only Word files, or keep PDFs in a separate folder

Companion video

Video: Convert Word to PDF Automatically in SharePoint with Power Automate | Add Button to SharePoint. The video fills File with the file name alone, and moves the PDF through one shared processing folder. The steps here use a path that also finds files in subfolders, and a folder for each run.

If the player is blocked on your network, open the video on YouTube.

Need help applying this to your own setup? Read about consulting.