Press "Enter" to skip to content

Convert SharePoint List Items to PDF with Power Automate

As a Microsoft community ‘Flownaught’ I spend (Jay Goodison) quite 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 which is raised often is ‘How to convert SharePoint list data to a PDF Document‘ and this post shows you how to do exactly that for both single and multiple items.

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

  1. Obtain SharePoint List Item Data
  2. Create a HTML Template
  3. Interlace the HTML with SharePoint List Item Data
  4. 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 – https://powerautomate.microsoft.com

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 simply place your cursor in the target location within the HTML and select the required response field from 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 into 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

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

1. Launch Power Automate – https://powerautomate.microsoft.com

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 selected 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, so please configure your HTML as required to build visually appealing documents.

Finally…

For these examples, we’ve used Encodians ‘Convert HTML to PDF‘ action. You could use the OneDrive ‘Convert File‘ action, however, there is limited HTML support so 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!

9 Comments

  1. ME Gauvin ME Gauvin

    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.”

  2. Zizheng Gao Zizheng Gao

    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?

  3. Jen Jen

    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?

    • Jay Gooodison Jay Gooodison

      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 Pranav Parmal

    The Issue has been fixed.

    Thank you 🙂

  5. Pranav Parmal Pranav Parmal

    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

Leave a Reply

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