Skip to main content

Generate an Invoice PDF in Power Automate: Line-Item Data to Document with PDF4me

9 min read
PDF4me Team

Generate Document (Single) is a PDF4me action for Power Automate that merges one data record into a Word template and returns a finished PDF. This walkthrough builds a five-step flow: two Dropbox fetches for the invoice data and the .docx template, PDF - Generate Document (Single) to merge them, and Create file to write the result. For invoices it handles the hard part, which is not the header fields but the line items: a table that has to grow to however many rows the data holds.

The short version

1. Manually trigger a flow → 2. Dropbox, Get file content using path for the invoice data → 3. a second Dropbox fetch, renamed Get Invoice Template, for the .docx → 4. PDF, Generate Document (Single) with Template File Type Docx (PDF4me Template Syntax), Document Data Type Json and Keep Pdf template Editable No → 5. Dropbox, Create file with File Content from the generate step.

Template File Type is the field that makes invoices work

Plain Docx does simple field substitution: one placeholder, one value. Pick plain Docx for an invoice and the line item table will render once, with the first record, and silently drop the rest. It is the most common thing to get wrong here and the output looks plausible, which is what makes it dangerous. Docx (PDF4me Template Syntax) understands the repeating constructs, which is how a single template row becomes nineteen rows when the data holds nineteen line items.

What you are automating​

Invoice templates look simple until you notice the table in the middle. Name and address are one value each. The line items are three rows this time and nineteen next time, and the totals underneath have to land in the right place either way. That repeating section is why invoices are built from templates rather than assembled by hand in a flow. Generate Document (Single) merges one data record into the template and returns the finished PDF, repeating section included.

At a glance​

  1. Manually trigger a flow
  2. Get file content using path (Dropbox) for the invoice data
  3. Get Invoice Template (Dropbox) for the .docx
  4. PDF - Generate Document (Single) (PDF4me)
  5. Create file (Dropbox)
The completed Power Automate run generating an invoice PDF, every step ticked green
The run this post was written from: trigger, two fetches, Generate Document (Single), Create file.

Five steps, and the whole thing ran in about 4 seconds.

Why this pattern works​

The template stays a Word file

Finance adds a VAT line, legal rewords the payment terms, marketing updates the logo. With the layout in a .docx in storage, those people edit a Word document, which they can already do. With the layout built inside the flow, every wording change becomes a Power Automate ticket.

One row, however many line items

Template File Type on Docx (PDF4me Template Syntax) handles the repeating row, so the table grows to as many rows as the data holds.

The data source is swappable

In production the data usually comes from the system that raised the invoice rather than from a file. Replace the first fetch with a query against your accounting system or database and everything downstream is unchanged.

What you need​

Checklist
  • The PDF4me PDF connector in your Power Automate environment.
  • A storage connection. This flow uses Dropbox.
  • Two files: an invoice .docx template, and a .json file with the invoice data.

Build the flow​

Step 1: Manually trigger a flow​

Add Manually trigger a flow.

Step 2: Get file content using path (Dropbox)​

Flow so far: trigger only.

  1. Add Dropbox: Get file content using path.
  2. File path: the JSON holding the invoice — customer, dates, line items, totals.
The first Dropbox step, fetching the invoice data JSON
Step 2: the JSON holding the invoice — customer, dates, line items, totals.

Step 3: Get Invoice Template (Dropbox)​

Flow so far: trigger, the data fetch.

  1. Add a second Dropbox: Get file content using path and rename it Get Invoice Template.
  2. File path: the Word template.
The second Dropbox step, renamed Get Invoice Template, fetching the .docx
Step 3: the template is fetched, not built in the flow.

Step 4: Generate Document (Single) (PDF4me)​

Flow so far: trigger, both fetch steps.

  1. Add PDF: Generate Document (Single).
  2. Set the five mappings below.
FieldValue hereNotes
Template File TypeDocx (PDF4me Template Syntax)Enables the repeating-row syntax
Template File NameNew_invoice_template.docx
Template File Datafrom the template step
Document Data TypeJson
Document Data Filefrom the data step
The PDF4me Generate Document Single step showing Template File Type Docx with PDF4me Template Syntax
Step 4: Template File Type carries the repeating-row behaviour.
  1. Output Type: PDF. Keep Pdf template Editable: No flattens the result. An invoice somebody can edit after you send it is not an invoice.
The rest of the same step, showing Output Type PDF and Keep Pdf template Editable No
The same step continued: Output Type and the editable flag.

The table syntax is documented in the Word template tables guide.

Step 5: Create file (Dropbox)​

Flow so far: trigger, both fetches, Generate Document (Single).

  1. Add Dropbox: Create file.
  2. Set the output folder.
  3. File Name: name it from the invoice number rather than the template. The field takes a dynamic expression, so pull the number out of the data you already have in the flow.
  4. File Content: from the generate step.
The Dropbox Create file step writing the finished invoice PDF
Step 5: File Content comes straight from Generate Document (Single).

Quick reference​

#ActionMain mapping
1Manually trigger a flow
2Get file content using pathFile path: the invoice .json
3Get Invoice TemplateFile path: the invoice .docx
4Generate Document (Single)Template File Type Docx (PDF4me Template Syntax), Document Data Type Json, template and data from steps 3 and 2
5Create fileOutput folder, File Name from the invoice number, File Content from step 4

Troubleshooting​

Only the first line item appears

Template File Type is plain Docx. Switch it to Docx (PDF4me Template Syntax).

Placeholders appear literally in the PDF

The names in the template do not match the keys in the JSON, and they are case sensitive.

Every invoice has the same filename

Build File Name from the invoice number in the data.

What to try next​

FAQ​

How do I generate an invoice PDF in Power Automate?​

Add the PDF4me Generate Document (Single) action, map a Word template and a JSON data file, set Template File Type to Docx (PDF4me Template Syntax), and write the result with Create file.

How do I handle a variable number of line items?​

Use the PDF4me template syntax rather than plain Docx, and build the table with the repeating row construct. The template holds one row; the output gets as many as the data has.

Can the data come from a database instead of a file?​

Yes. Replace the first fetch step with whatever queries your system and pass the result to Document Data Text instead of Document Data File.

Can I generate many invoices at once?​

Yes, with Generate Documents (Multiple), which takes many records and returns one PDF each.

The template belongs to finance. The flow just fills it in.