Forum Discussion

grivonberg's avatar
grivonberg
Copper Contributor
May 02, 2024

Sharepoint document conversion

So, our client wants to use Sharepoint to organize and store their files in a centralized location. This wouldn't be incredibly difficult but they also want every file to be converted to a .pdf. This means any .doc, .docx, .txt. and even .xlsx files.

We were looking at a tool inside of Sharepoint called PowerAutomate and I was wondering if anyone found success using that app to convert files -- or if anyone has a better suggestion on how to accomplish this.

Thanks so much in advance!

  • grivonberg Power Automate is one of the Office 365 apps and usually I build flows direct in the web interface at make.powerautomate.com rather than do so from within SharePoint, but the choice is yours and the method is the same. It's not difficult to build a flow to convert a document to PDF and I've shown a flow below that I used for a lunch & learn at my company specifically for this. I used the classic designer but you also build it in the new designer.

     

    In this example the flow is triggered from a JSON-formatted button in the document library but you need to build the flow first before doing the button formatting: We're going to convert the Word document Consultation-Site Storage.docx to a PDF and the flow will add it to the PDF folder in the library.

     

     

    1. In your flow the trigger will be the SharePoint for a selected file trigger

     

     

    2. Next add the SharePoint get file properties action and for the Id field select ID from the dynamic content box:

     

     

    3. Next add a SharePoint get file content action and for the File Identifier field select Identifier from the dynamic content box.

     

     

     

    4. Next add a OneDrive create file action. Select where in your OneDrive you want to store the document, I've just put it in the root / and it does this as a half way house between the original file and the PDF. Select file name with extension and file content from the dynamic content box.

     

     

    5. Next, add the OneDrive convert file using path action. Don't worry that it says Preview, it's said that since 2018!. For the File Path select Path and make sure the target type is set to PDF.

     

     

    6. Add a SharePoint create file action, select the site and folder path where the PDF will be saved to. For the file name field select Name from the dynamic content box and type .pdf after it. Select file content from the convert file using path section of the dynamic content box.

     

    Finally give your flow a name and save it. and then copy the ID of the flow as you'll need this for the button:

     

     

     

     

    Back in your SharePoint library create a single line of text column and format it in advanced mode with the following JSON adjusting text and colors etc to your preferences, and paste in the ID of your flow:

    {
    "elmType": "button",
    "txtContent": "Convert to PDF",
    "customRowAction": {
    "action": "executeFlow",
    "actionParams": "='{\"id\":\"8125634b-6718-4718-84e4-f9a29567276d\", \"headerText\":\" ' + [$Title] + '\",\"runFlowButtonText\":\"Convert\"}'"
    },
    "style": {
    "background-color": "#fff5dd",
    "border-radius": "10px"
    }
    }

     

     

    When you click the button the run flow panel will open on the far right of the screen and the flow will run when you click the Convert button at the bottom.

     

     

    This is the result:

     

     

     

    Rob
    Los Gallardos
    Microsoft Power Automate Community Super User.
    Principal Consultant, SharePoint and Power Platform WSP Global (and classic 1967 Morris Traveller driver)

     

     

     

  • Rob_Elliott's avatar
    Rob_Elliott
    Bronze Contributor

    grivonberg Power Automate is one of the Office 365 apps and usually I build flows direct in the web interface at make.powerautomate.com rather than do so from within SharePoint, but the choice is yours and the method is the same. It's not difficult to build a flow to convert a document to PDF and I've shown a flow below that I used for a lunch & learn at my company specifically for this. I used the classic designer but you also build it in the new designer.

     

    In this example the flow is triggered from a JSON-formatted button in the document library but you need to build the flow first before doing the button formatting: We're going to convert the Word document Consultation-Site Storage.docx to a PDF and the flow will add it to the PDF folder in the library.

     

     

    1. In your flow the trigger will be the SharePoint for a selected file trigger

     

     

    2. Next add the SharePoint get file properties action and for the Id field select ID from the dynamic content box:

     

     

    3. Next add a SharePoint get file content action and for the File Identifier field select Identifier from the dynamic content box.

     

     

     

    4. Next add a OneDrive create file action. Select where in your OneDrive you want to store the document, I've just put it in the root / and it does this as a half way house between the original file and the PDF. Select file name with extension and file content from the dynamic content box.

     

     

    5. Next, add the OneDrive convert file using path action. Don't worry that it says Preview, it's said that since 2018!. For the File Path select Path and make sure the target type is set to PDF.

     

     

    6. Add a SharePoint create file action, select the site and folder path where the PDF will be saved to. For the file name field select Name from the dynamic content box and type .pdf after it. Select file content from the convert file using path section of the dynamic content box.

     

    Finally give your flow a name and save it. and then copy the ID of the flow as you'll need this for the button:

     

     

     

     

    Back in your SharePoint library create a single line of text column and format it in advanced mode with the following JSON adjusting text and colors etc to your preferences, and paste in the ID of your flow:

    {
    "elmType": "button",
    "txtContent": "Convert to PDF",
    "customRowAction": {
    "action": "executeFlow",
    "actionParams": "='{\"id\":\"8125634b-6718-4718-84e4-f9a29567276d\", \"headerText\":\" ' + [$Title] + '\",\"runFlowButtonText\":\"Convert\"}'"
    },
    "style": {
    "background-color": "#fff5dd",
    "border-radius": "10px"
    }
    }

     

     

    When you click the button the run flow panel will open on the far right of the screen and the flow will run when you click the Convert button at the bottom.

     

     

    This is the result:

     

     

     

    Rob
    Los Gallardos
    Microsoft Power Automate Community Super User.
    Principal Consultant, SharePoint and Power Platform WSP Global (and classic 1967 Morris Traveller driver)

     

     

     

Resources