Convert SharePoint List Items to PDF with Power Automate

January 15th 2020
Back to all blogs

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!

Author
Jay Goodison

Managing Director

Back to all blogs

You might also be interested in...