Convert SharePoint Uploaded Word File to Pdf

Yawer IqbalDyn365CE3 years ago20 Views

Did you ever receive a requirement that a Word file uploaded through a model-driven app in SharePoint should be converted and saved as Pdf? I had this requirement in multiple projects. Recently I have used cloud flow to achieve this. It was a model-driven app that has integration with SharePoint for document storage. In this post, I m documenting steps.

Summary

The app has SharePoint integration enabled for the “Account” table (this post does not cover how to integrate SharePoint with Model Driven Apps, follow this link for integration details). Flow triggers when a file is uploaded from Model Driven App and created in SharePoint document library. It then uses that uploaded Word file and creates Pdf copy, and finally delete the Word version. For explaining steps, I will use the following document URL, this file was uploaded by my model-driven app:

https://mydomain.sharepoint.com/sites/Documents/account/test_67B9406FCBB7EB118236000D3A6A4A8A/vr.docx

Steps

  1. Create a cloud flow and add “When a file is created (properties only)” trigger. Configure the following properties:
    • Site Address
    • Library Name

We don’t want to trigger this flow on any file upload; rather, we want to trigger it only when a word file is created. Configure “Trigger Conditions” for word file extensions “.doc” and “docx”.

Here are expressions:

@contains(triggerBody()?[‘{FilenameWithExtension}’],’.docx’)
@contains(triggerBody()?[‘{FilenameWithExtension}’],’.doc’)

2. Initialize a string type variable “DocumentsFolderName ” to hold the subdirectory name. This is the container folder for all attachments of Model-Driven App table. Since I have configured document upload for “Account” table, its value is “account” for me. The expression in the following action will use this variable.

3. Initialize another string variable “FileNameWithPath” and use the following expression as value:

concat(replace(triggerOutputs()?[‘body/{Path}’],variables(‘DocumentsFolderName’), ”), triggerOutputs()?[‘body/{FilenameWithExtension}’])

What does this expression do?

Let’s use our example document URL, which is:

https://mydomain.sharepoint.com/sites/Documents/account/test_67B9406FCBB7EB118236000D3A6A4A8A/vr.docx

this variable will hold /test_67B9406FCBB7EB118236000D3A6A4A8A/VR.docx as value to be used in next steps.

4. Initialize string variable “NewFileNameWithExtension” and assign given expression as value:

concat(triggerOutputs()?[‘body/{Name}’], ‘.pdf’)

5. Convert Word document to Pdf, use action and do the following configs:

“Location” and “Document Library” should remain same (where Word document was uploaded). Assign “FileNameWithPath” variable as value in “File”.

6. Use SharePoint Create file action and configure as below:

  • Site Address should be same SharePoint site
  • Folder Path: assign trigger’s “Folder path”
  • File Name: use “NewFileNameWithExtension” variable
  • File Content: use output from, Convert Word Document to Pdf, previous step

7. Configure SharePoint (Delete file action) to delete original Word file

Use trigger’s Identifier in “File Identifier” field.

and that’s it, this flow will convert any word document uploaded to Pdf asynchronously.

Let’s Connect

 twIcon lnIcon fbicon

Original Post https://yaweriqbal.com/2021/05/20/convert-sharepoint-uploaded-word-file-to-pdf/

0 Votes: 0 Upvotes, 0 Downvotes (0 Points)

Leave a reply

Join Us
  • X Network2.1K
  • LinkedIn3.8k
  • Bluesky0.5K
Support The Site
Events
March 2025
MTWTFSS
      1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31       
« Feb   Apr »
Follow
Sign In/Sign Up Sidebar Search
Popular Now
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...