This post demonstrates how to create a PDF invoices from JSON data using Microsoft Power Automate (Microsoft Flow). The five step flow follows this sequence:
- Receive data from a HTTP request containing a JSON payload.
- Populate a Microsoft Word Template.
- Create File (Word Document).
- Convert previously created Word document to PDF.
- Save the PDF File.

The source data is line printer data from a legacy version of a Kerridge Autoline system based on KCML. Microsoft Flow is an easy way to add functionality to old or legacy systems without spending a lot of money.
Here is a sample of the original line printer text:
Page No: 1 Inv no. 00102707 Acc no. 0000024 Date 28/11/2019 Invoice to: Deliver to: Sandy Lane Garage Sandy Lane Garage 12 Sandy Lane 12 Sandy Lane Walton-On-Thames Walton-On-Thames Surrey Surrey KT12 2EQ KT12 4EQ VAT NO: FR86329130660 Order no. Order Date 088135 28/11/2019 Part No. Description Qty Price Disc Value 02/200073 HOSE* 1 12.00 0.00 12.00 02/200147 THERMOSTAT GASKET 1 0.66 0.00 0.66 02/202278 GASKET - ROCKER COVER P12 1 4.50 0.00 4.50 1450/0002 GREASE NIPPLE 10 0.25 0.00 2.50
You can see the complete listing here on Pastebin. Here is the final PDF produced by flow from the data above (click here to see full PDF):
I wrote a shell script to convert the line printer data to JSON using grep, sed and awk. You can see the JSON code here on Pastebin. Next I built a Microsoft Word template that would be the destination for the data.
Create a Word Template for the PDF Invoice
I used the Simple Sales Invoice in the Word template gallery as my starting point and modified the appearance to my liking.
Next, plain text control controls were added to the Invoice for each of the fields in the JSON file that will appear only once (i.e. everything that is not part of an Invoice line). Do the following:
- Enable the Developer Tab in Word.
- Put the cursor into a table cell where your data needs to go.
- Enter some sample data into that cell.
- Highlight the sample data and click on “Plain Text Context Control” in the developer toolbar.
- Click on Properties in the control toolbar ribbon.
- Give the content control a meaningful name(preferably match it to your JSON field names).

Add Content Controls for repeating data
For the repeating data, follow the same procedure as above for each column of data in your invoice line table, but this time make sure the field names match the JSON field names. Then specify the row as repeating content like this:

- Select the entire Invoice line item row. I find it is easiest to go to the Layout tab and click “Select” and then choose “Select Row”.
- Go back to the developer tab and click on the repeating section content control.
- Name the repeating section with a sensible name.
In this example, the JSON for a single invoice line is like this:
{ "PartNo": "813/00419", "Description": "GASKET-EXHAUST FLANGE", "ToInvoice": "1", "SellingPrice": "0.50", "DiscountPercentage": "0.00", "NetLineValue": "0.50" }
Set Repeating Column Headers
My example data has quite a lot of invoice lines which do not all fit on a single page. So it is important to make sure that “Repeat Header Rows” is enabled. This will ensure the subsequent pages have column headings.
Select the top row of your Invoice lines table and go to the Layout tab and select “Repeat Header Rows”.

Now that you have finished editing the Word document. Save it somewhere you will be able to access it from Flow, such as OneDrive or SharePoint.
Create the Flow
The flow is really easy to build and in this example there are only five steps:
- Step 1 – Create a new flow
- Choose “Instant – from blank”
- Trigger the flow “When a HTTP request is received”
- When the flow editor appears click the “Generate from Sample” button within the HTTP Request flow part and paste in a sample of your JSON data and then flow will automatically generate the JSON schema which you will be able to use in the rest of the flow.
- Step 2 – Add the “Populate a Microsoft Word Template” action.
- Select the previously saved template file.
- Flow will read the document and present a list of fields to be added to the document.
- Go through each field and add them to the document, apart from the repeating fields.
- When you reach the line items block it will first appear like this:
- Click on the little box I have highlighted in red which switches the input to accept an entire array. Then you can select the aeeay from your JSON file.
- Step 3 – Save the File
- Now your Word document has been populated you can save it somewhere that is appropriate for your environment (I used “Create file – OneDrive for Business).
- For the Filename I used “INV_” + Invoice Number from JSON File + “.docx”:
- Step 4 – Convert the Word Invoice to PDF using the path from the previous step.
- Step 5 – Save the new PDF. I named the file as per the above step but changed the extension to .PDF
Executing the Flow
This flow is triggered via a HTTP request with a JSON payload. In this example it was fired using cURL from Linux like this:
#!/bin/bash host="https://prod-84.westeurope.logic.azure.com:443/workflows/..." curl -v -d @INV_00102707.json -H 'Content-Type: application/json' $host
But it could just as easily be executed from PowerShell like this:
$FlowUri = "https://prod-84.westeurope.logic.azure.com:443/workflows/..." $PostBody = Get-Content ".\INV_00102707.json" Invoke-RestMethod -Method Post -Uri $FlowUri -Body $PostBody
Conclusion
Microsoft Flow can provide a good solution for automatically generating invoices or other business documents. In it’s live implementation this flow will also:
- Save the document to a SharePoint list in a custom content type:
- Metadata saved with the item.
- Easy lookups.
- Will create a simple document management system within 365.
- Use a Sendgrid template to email the invoice to the recipient.
- Will transmit relevant data to a Power BI Streaming dataset to allow for easy analysis of invoicing.
I was frustrated that I couldn’t find an easy way to format numbers in flow so that there are thousands separators etc. But it is a minor complaint.