In this post, I will be covering how we can share documents (non pdf) uploaded to SharePoint library in pdf format with users, using Microsoft Flow.
Lets take the default Documents library and upload some documents (excel, word or pdf) etc to it.

Create Flow
- Login to https://flow.microsoft.com
- Click on “My Flows” -> “New” -> “Create from blank”

Get File
This trigger can be anything like when file is uploaded or when file is modified etc.
- In the search box, type “for a selected file” and under triggers click on “For a selected file”

- Select “Site URL” and “Library”

Get File Properties (Optional)
Required only if specific files need to be processed (based on file properties like file name etc.)
- Click “New Step”. In the search box, type “get file properties” and under triggers, select SharePoint trigger “Get file properties”.

- Select “Site Address” and “Library” .
- Click on “Add dynamic content” below “Id” textbox. From the floating dialog, select “FileId”.
- Click on “Save” to save the progress

Note: Catch in this step, “FileId” content is not present or dynamic content floating window will not show any output variables from previous step, if library selected is a “Modern” library. The workaround here is, after adding the second step, select any classic library from any Site Address in previous step and then you can see output variables in dynamic content of second step
Get File Extension (Optional)
Required only if files with specific extension need to be processed
- Add new step “Initialize Variables”. Rename it to “Get File Name” and set the name to “filename”, type to “string” and value to “file name with extension”

- Add new step “Initialize Variables”. Rename it to “Get FileName Length” and set the name to “namelength”, type to “Integer” and value to expression “length(variables(‘filename’))“

- Add new step “Initialize Variables”. Rename it to “Get Extension Length” and set the name to “extlength”, type to “Integer” and value to expression “sub(variables(‘namelength’),lastIndexOf(variables(‘filename’),’.’))”

- Add new step “Initialize Variables”. Rename it to “Get File Extension” and set the name to “fileextension”, type to “String” and value to expression “substring(variables(‘filename’),lastIndexOf(variables(‘filename’),’.’), variables(‘extlength’))”

Condition Check (Optional)
This step is required if above optional steps are used in the flow. This adds the logic to process files with specific extensions.
- Add new step “Condition”. Set the parameters to check if file extension is not pdf.

Create File in Onedrive
All the steps defined under “If yes” block can be added directly after step “Get File”. if Optional steps are not used.
- Under “if yes” block, click “Add an action” and search for “Get file content” and select the one for SharePoint. Set Site Address to “Site URL” and File Identifier to “Identifier” (dynamic content from Get File Properties)

- Add new action “Create File” for Onedrive. Set folder path to “/” (for root folder or else select specific folder), file name to “File name with extension” (dynamic content) and file content to “File Content” (dynamic content).

- Add new action “Convert File” for Onedrive. Set File to “Id” (dynamic content from Create File).

- Add new action “send an email (V2)”. Set parameters like To, Subject, Body etc. Under attachments, select attachment name as “File Name” and attachment content as “File Content” (dynamic content from Convert File)

Delete File (Optional)
This step is required only if you want the file to be deleted which was created as part of the above process,
- Add new action “Delete file” for Onedrive. Set parameter File as “Id” (dynamic content from Create File).

- Click “Save” to save the progress.
- Rename the flow to “pdf conversion” or any other name and click “Save”.
Complete Flow Diagram

Condition Block

Test Flow
- Navigate to “Documents” library and select any file.
- Under flow, select “pdf conversion”.

- Verify the connections and continue.
- Check the mailbox for file attachment and also the file in Onedrive
Hope this helps someone with same requirement.
Note: Since there is no “Convert File” action is available for SharePoint, Onedrive for business actions like “Create File”, “Convert File” etc. are used in the process.
Some actions are still in preview so use in production is not suggested. Check this link for preview program – https://flow.microsoft.com/en-us/blog/flow-preview-program/
Hi Danny,
Thank you for your post. Do you know how to convert a SharePoint form in infopath to pdf?
Regards,
Daniel
LikeLike
I have been trying to make this step work for one of my libraries for a full week. Your steps were the first to walk me through all the steps to make it work. Thank you!
LikeLiked by 1 person
Me again – it also worked to save a copy of the PDF in another folder as the last step, when I replaced the email step.
LikeLiked by 1 person
Glad it helped
LikeLike
Thanks in support of sharing such a nice idea, piece of
writing is pleasant, thats why i have read it
completely
LikeLike
Hi, I think your site might be having browser compatibility issues. When I look at your blog in Ie, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, awesome blog!
LikeLike
pretty! This was a really wonderful post. Thank you for your provided information.
LikeLike
Appreciate the recommendation. Let me try it out.
LikeLiked by 1 person