Showing results for 
Search instead for 
Did you mean: 

Create PDF document from HTML template based on dynamic data in Microsoft Flow

This article demonstrates how to generate PDF document from an HTML template with the help of Microsoft Flow.


I will use actions from Plumsail Documents connector, which is a part of Plumsail Actions.


We will firstly generate HTML document from a template. Then we will convert it to PDF. In this article, we will generate PDF invoice based on some data. This is how our final PDF file looks:

Result PDF file

Our template and result document have to be stored somewhere. Microsoft Flow has a lot of connectors for different systems. Here are just a few of them:

  • SharePoint
  • Salesforce
  • Box
  • OneDrive
  • Google Drive
  • Dropbox
  • SFTP
  • File System

You can store your files anywhere. In this example, we will store our documents in SharePoint. Our flow will use JSON object as a source data for the template, but you can get data from other sources. For example, query list items from SharePoint or from Salesforce.


This is how our flow looks:

Result text file


Here is step by step description for the flow.


Flow trigger

You can actually pick any trigger. For example, you can start Flow on file creation in a SharePoint document library. We use "Manually trigger a flow" trigger here to simplify the Flow.


Get file content

This action gets file content of the specified file from a SharePoint document library. You just specify SharePoint site URL and path to your file. We use this action to read HTML template.

You can use any other connector to get files from your system.


Create HTML from template

This is an action from Plumasail Documents connector, which is a part of Plumsail Actions. This action is suitable for generation of HTML and text documents.

You can find more information about this action here.

There are two parameters:

  1. Source HTML
  2. JSON

In the first parameter 'Source HTML' you can put raw HTML/text of a template or file content of a template from some other action. We specified the output of the previous action as a template. The internal file is quite large because of CSS styles. The template below is just a part of the template with a snippet for invoice items. Use this link to download the complete template.

        <tr id="header_row">
            <th class="index_th">#</th>
            <th class="left details_th">Title</th>
            <th class="quantity_th">Quantity</th>
            <th class="unitprice_th">Unit Price ($)</th>
            <th class="subtotal_th">Subtotal ($)</th>
            <tr id="total_tr">
                <td colspan="2">&amp;nbsp;</td>
                <td colspan="2" class="total" id="total_currency"><span class="currency">$</span> Total </td>
                <td class="total"> ${{Total}} </td>
            {{#each Items}} {{#with FieldValues}}
            <tr class="item">
                <td class="item_l"> {{#index}} </td>
                <td class="item_l"> {{Title}} </td>
                <td class="item_r"> {{Quantity}} </td>
                <td class="item_r"> {{UnitPrice}} </td>
                <td class="item_r"> {{SubTotal}} </td>
            {{/with}} {{/each}}

You may see that there are placeholders like {{Total}} and {{Quantity}} in the template. There is also #{{each}} iterator for rendering invoice items. Please read template syntax description for more information.

In the second parameter, we specified data to apply to the template in JSON format. This object contains information for invoice header and for invoice items:

    "InvoiceDate": "10/02/2017",
    "InvoiceNum": 1,
    "Total": 1098,
    "ClientCompany": "Contoso ltd.",
    "ClientName": "John Doe",
    "ClientAddress": "55 East 52nd Street 21st",
    "ClientCity": "New York",
    "ClientRegion": "US",
    "ClientZip": "10022",
    "Items": [
            "FieldValues": {
                "Quantity": 1,
                "SubTotal": 499,
                "Title": "Product Name #1",
                "UnitPrice": "499"
            "FieldValues": {
                "Quantity": 1,
                "SubTotal": 599,
                "Title": "Product Name #2",
                "UnitPrice": 599


Convert HTML to PDF

This is also an action from Plumasail Documents connector.

Just put HTML file content from the output of the previous action and receive PDF file content as an output of this action. You can also use raw HTML string as a source HTML.

You can find more information about this action here.


Create file

Now you need to store text file somewhere. In our example, we use 'Create file' action from SharePoint connector to store the PDF document into SharePoint document library.

Select fields

You can use any other connector to store text document into your system.


There are more examples in Plumsail Actions documentation.


This post was originally posted here.

Meet Our Blog Authors
  • Working daily with Microsoft Cloud to deliver the needs of my company, my customers and various Microsoft communities and forums. | Office 365 | Flow | PowerShell | PowerApps | SharePoint |
  • Co-founder of, Office 365 and SharePoint expert. Passionate about design and development of easy to use, convenient and flexible products.
  • Microsoft Business Apps MVP. Owner of ThriveFast, an Office 365 consulting company.
  • 7x Microsoft Business Solutions MVP (CRM)
  • I'm keen in MS technologies, SharePoint, Office 365 and development for them
  • Daniel is a Business Productivity Consultant & Microsoft Business Solutions MVP who is very enthusiastic about all things Office 365, Microsoft Flow, PowerApps, Azure & SharePoint (Online). Since the preview, Daniel has been working with Microsoft Flow and later on with Microsoft PowerApps. That led to him being awarded an MVP Award for Business Solutions. He loves to blog, present and evangelize about improving productivity in the modern workspace with these amazing tools!
  • Michelle is an Office 365 solution architect in Twin Cities, MN. She has been delivering business collaboration solutions for years with her focus on SharePoint and Office 365. Michelle is a recent board member of the Minnesota Office 365 User Group and has been a member of the SharePoint community since 2009. She is a frequent speaker at MNSPUG and SharePoint Saturday and co-chaired the Legal SharePoint User Group for 4 years. Her most frequent projects have involved rolling out a large deployment of Office 365, SharePoint Online intranet, build of a "CHAMPS" Office 365 user adoption program and most recently, SharePoint On-Premise to Online Migration. Michelle is very excited about cloud technology as it is shifting her IT Pro focus to collaboration strategy and technical adoption.
  • I'm a Microsoft Office Servers and Services MVP with a special interest in SharePoint, Office 365, Microsoft Flow, Microsoft Teams and PowerApps. I work at Triad Group Plc (
  • Passionate #Programmer #SharePoint #SPFx #Office365 #MSFlow | C-sharpCorner MVP | SharePoint StackOverflow, Github, PnP contributor