for Microsoft Power Automate and Azure logic apps

Convert SharePoint List Items to PDF

By Jay Goodison

15th January 2020

Convert SharePoint List Items to PDF with Power Automate

As a Microsoft community ‘Flownaught’, I spend (Jay Goodison) a lot of my working week helping users on the Microsoft Power Automate Community. It’s a fantastic resource for anyone who needs help building solutions with Microsoft Power Automate!

A topic raised often is ‘How to convert SharePoint list data to a PDF Document’, and this post shows you how to do precisely that for single and multiple items.

For both these example Flows, the overall approach is pretty much the same:

  • Obtain SharePoint List Item Data
  • Create a HTML Template
  • Interlace the HTML with SharePoint List Item Data
  • Convert the HTML to PDF

For both of these examples, I have created a SharePoint list containing ‘Orders’, configured as follows:

Convert a single SharePoint List Item to PDF

For this example, we’ll configure a Flow to automatically convert every new order (SharePoint List Item) to PDF upon creation.

1. Launch Power Automate

2. Create a new ‘Automated flow.

3. Provide the following information:

3.a. Flow name: Enter a relevant name/description for the Flow

3.b. Select the SharePoint ‘When an item is created‘ trigger action

3. c Click ‘Create.

4. Configure the trigger action:

4.a. Site Address: Set to the target SharePoint site

4. b List Name: Set to the target SharePoint list

5. Add the Encodian ‘Convert HTML to PDF‘ action

5.a. Filename: Enter the name of the output file (pdf). You may wish to generate a unique filename by using the concat expression such as:

concat('NewOrder-',utcNow(),'.pdf')

5. b. HTML Data: Copy and paste the HTML data into the field. This demonstration uses this simple HTML snippet:

<html>
	<head>		
		<meta charset="UTF-8">
	</head>
	<body style="font-family:arial">
		<div style="padding-left: 12px;">
			<h2>Encodian - New Order</h2>
		</div>
		<div>
			<table style="width: 100%;"  cellpadding = "10">
				<tbody>
					<tr>
						<td><b>Submitted By<b></td>
						<td></td>
						<td><b>Submitted On<b></td>
						<td></td>
					</tr>
					<tr>
						<td><b>Customer Name<b></td>
						<td></td>
						<td><b>Customer Email<b></td>
						<td></td>
					<tr>
						<td><b>Customer Address<b></td>
						<td></td>
						<td>Order Status</td>
						<td></td>
					</tr>
					<tr>
						<td><b>Purchase Order<b></td>
						<td></td>
						<td><b>Order Details<b></td>
						<td></td>
					</tr>
					<tr>
						<td colspan="2"><b>Other Information<b></td>
						<td colspan="2"> </td>
					</tr>
				</tbody>
			</table>
		</div>		
	</body>
</html>

5. c. To interlace the list item data, place your cursor in the target location within the HTML and select the required response field from the dynamic data

6. Add a ‘Create File‘ SharePoint action

6.a. Site Address: Set to the target SharePoint site

6. b. Folder Path: Set to the target SharePoint library and folder

6.c. File Name: Select the ‘Filename‘ field from the ‘Convert HTML to PDF‘ action

6.d. File Content: Select the ‘File Content‘ field from the ‘Convert HTML to PDF‘ action

7. Test the Flow by submitting a new item to the list.

8. Validate the flow run has successfully executed

9. Check the PDF document has been created

We have used very simple HTML for this example. The Encodian ‘Convert HTML to PDF‘ provides full HTML5 / CSS3 support with many configuration options, so please configure your HTML as required to build visually appealing documents.

Convert multiple SharePoint List Items to PDF

We’ll configure a Flow for this example to convert all orders into a PDF document automatically. This could be executed on a schedule and perhaps query items in a specific state. However, we’ll focus on converting multiple list items into a PDF document for this example.

1. Launch Power Automate 

2. Create a new ‘Instant flow.

3. Provide the following information:

3.a. Flow name: Enter a relevant name/description for the Flow

3.b. Select the SharePoint ‘Manually trigger a flow‘ trigger action

3. c Click ‘Create.

4. Add a SharePoint ‘Get items‘ action and configure:

4.a. Site Address: Set to the target SharePoint site

4. b List Name: Set to the target SharePoint list

TIP: Add a filter query or select a specific SharePoint list view to filter the data returned by the ‘Get items’ action.

5. Add a ‘Select‘ action

5.a. From: Select the ‘value‘ property from the SharePoint ‘Get items‘ action

5. b. Use the ‘Map’ fields to provide headings for each list item column you wish to display in the resulting document.

6. Add a ‘Create HTML Table‘ action

6. b. From: Select the ‘Output‘ property from the ‘Select‘ action

7. Add the Encodian ‘Convert HTML to PDF‘ action

7.a. Filename: Enter the name of the output file (pdf). You may wish to generate a unique filename by using the concat expression such as:

concat('Orders-',utcNow(),'.pdf')

7. b. HTML Data: Copy and paste the HTML data into the field. This demonstration uses this simple HTML snippet:

<html>
	<head>		
		<meta charset="UTF-8">
	</head>
	<body style="font-family:arial">
		<div style="padding-left: 12px;">
			<h2>Encodian - Orders</h2>
		</div>
		<div>
			
		</div>		
	</body>
</html>

7.c. To interlace the HTML table within the HTML data as follows:

8. Add a ‘Create File‘ SharePoint action

8.a. Site Address: Set to the target SharePoint site

8.b. Folder Path: Set to the target SharePoint library and folder

8. c. File Name: Select the ‘Filename‘ field from the ‘Convert HTML to PDF‘ action

8.d. File Content: Select the ‘File Content‘ field from the ‘Convert HTML to PDF‘ action

7. Test the Flow by manually starting

8. Validate the flow run has successfully executed

9. Check the PDF document has been created

We have used very simple HTML for this example; the Encodian ‘Convert HTML to PDF‘ provides full HTML5 / CSS3 support with many configuration options. Please configure your HTML as required to build visually appealing documents.

Finally…

We’ve used Encodians ‘Convert HTML to PDF’ action for these examples. You could use the OneDrive ‘Convert File‘ action. However, there is limited HTML support, so that you may run into unexpected issues.

We hope you’ve found this guide useful, and as ever, please share any feedback or comments – all are welcome!

23 Comments

  1. ME Gauvin says:

    Hi, in this example flow, is it possible to create a file in OneDrive instead of Sharepoint? I am getting the following error:
    “Unable to process template language expressions in action ‘Create_file’ inputs at line ‘1’ and column ‘2883’: ‘The template language expression ‘json(decodeBase64(triggerOutputs().headers[‘X-MS-APIM-Tokens’]))[‘$connections’][‘shared_onedriveforbusiness’][‘connectionId’]’ cannot be evaluated because property ‘shared_onedriveforbusiness’ doesn’t exist, available properties are ‘shared_encodiandocumentmanager, shared_flowpush, shared_sharepointonline’. Please see https://aka.ms/logicexpressions for usage details.”

    1. Jay Gooodison says:

      Hey, yes of course, you can save the document to any location you just need to use the relevant action. To resolve your error please refer to this post: https://blog.encodian.com/2019/09/fix-the-invalidtemplate-unable-to-process-template-language-expressions-in-action-in-microsoft-flow/

  2. Zizheng Gao says:

    Hi Jay,
    This is an awesome flow demo.

    However, I am not getting the same user interface as you have posted here when I chose the “Convert from HTML to PDF”.
    Here is what I get

    “Connection Name”

    “*API Key”

    Do you know of the cause?

    1. Jay Gooodison says:

      Hi Zizheng Gao,
      Yes 🙂 – you need to sign-up for an API key here: https://www.encodian.com/apiKey
      The following article details how to setup the connection (it’s very simple): https://support.encodian.com/hc/en-gb/articles/360012267353-Create-an-Encodian-Connector-in-Flow
      HTH
      Jay

  3. Jen says:

    My Sharepoint list has several choice fields that appear as “Field Name Value” in Dynamic Content. When I try to insert one of these fields into the HTML code, Power Automate creates an “apply to each” step. How can I concatenate values from a choice field to insert them in the HTML code?

    1. Jay Gooodison says:

      Hi Jen,
      I would create a variable then as you loop through the SharePoint columns values simply append them to the variable… or in the SharePoint list create a new calculated column (datatype: single line of text) passing in the choice columns value, you then use the new column in your Flow rather than looping through the values. The PowerAutomate community is a good resource for general Power Automate questions – https://powerusers.microsoft.com
      HTH
      Jay

  4. Pranav Parmal says:

    The Issue has been fixed.

    Thank you 🙂

  5. Pranav Parmal says:

    There is any way to add an image to the pdf through the same flow.
    We need to add the company logo to the pdf

    1. Jay Gooodison says:

      Hi Pranav
      Sure, use the Image Watermark action – https://support.encodian.com/hc/en-gb/articles/360012485874-Add-Image-Watermark-Advanced
      If you need any help please contact support
      Thanks J

  6. Dave Lynch says:

    Hi, Can I create a template of a document getting the details from share point to populate in the template and save that as a pdf document in sharepoint folder?

    1. Jay Gooodison says:

      Hi Dave,
      Absolutely, this post covers how to update data in either a word or PDF document – Populate a Word or PDF Document using Power Automate
      Once you have updated the word document you can save to SharePoint using the standard SharePoint ‘Create File’ or ‘Update File’ actions
      HTH
      Jay

  7. Laura LaMalva says:

    Hi Jay – is there a way I can add attachment file names that I got with a get attachments/get attachment content and appended to an array? I don’t see an option to pick my array variable under Dynamic Content.
    Thanks in advance –
    Laura

    1. Jay Goodison says:

      Hi Laura,
      Please check out this video which should help: https://www.youtube.com/watch?v=_BItGsUvxWw
      HTH
      Jay

  8. Ric says:

    This is great! I was trying to create a button to open and print the generated pdf, cant find the solution

    1. Jay Goodison says:

      Hi Ric, you should look into Power Automate RPA to open and then print a document. HTH

  9. Anugrah Aneesh says:

    Hi, is there a way to covert only SELECTED ITEMS (not a single item) form a list to PDF?

    1. Jay Goodison says:

      Hi, if you’re using a Microsoft SharePoint trigger action… then no there isn’t as these triggers only support a single item. Early next year we are releasing a solution for this. HTH

  10. Aegir Brands says:

    Hi Jay,

    Great post. Is there a way to add multiple images from a SharePoint image library to the HTML/PDF?

    1. Jay Goodison says:

      Hi Aegir,
      Yes, please refer to the following post detailing how to add images from SharePoint to HTML: https://blog.encodian.com/2020/07/converting-html-to-pdf-or-word-with-power-automate/
      The post works with attachments but just use ‘Get file content’ to obtain an image… if you are working with multiple images you’ll need to consider where you are placing them… you could simply build a create an array variable and iteratively append each dataUri, then embed the variable in the HTML markup.
      HTH
      Jay

  11. Raphael says:

    Hi, i have a sharepoint list with a couple of images on each item as attachments that is connected to powerapps.
    i would like to know if i can have a flow that puts each item, along with their respective images, into a single PDF. The items would be filtered on powerapps, so it wouldnt be all items in the sharepoint list.

    1. Jay Goodison says:

      Hi, you could either configure your PowerApp to pass an array of list item ID’s and iterate the array within Power Automate, or pass the filter criteria and apply this to the ‘Get Files’ action in Power Automate. In essence Power Automate will simply obtain the list items you have configured it to retrieve. HTH Encodian

  12. Matt Edwards says:

    Hello. I followed your flow and it works great so thanks. Is it possible to get the PDF’s generated by new item in sharepoint to save with individual filenames? At the moment all the PDF’s are created with the same filename.

    1. Jay Goodison says:

      Hi Matt, you can names the files with whatever filename you require. When you call the ‘Create File’ action just use what ever logic / Power Automate Dynamic Data you require to set the filename property. HTH Jay

Leave a comment

Your email address will not be published. Required fields are marked *