Skip to main content

Generate Invoice from HTML Template: Ship Pixel-Perfect PDF Invoices from Make

14 min read
PDF4me Team

If your invoice layout already exists as HTML and CSS, rebuilding it as a Word document to automate it is work nobody should have to do twice. Keep the HTML. This walkthrough fills it with data and turns the result into a PDF, in Make, with PDF4me Generate Document and PDF4me Convert HTML to PDF. Five modules, two of which feed one action, and an Output Type field that will not give you a PDF no matter how much you want it to.

The scenario at a glance
1. Download a File

Dropbox module reading invoice_template.html, the layout.

2. Download a File

Dropbox module reading invoice_data.json, the values.

3. Generate Document

PDF4me module. Template File Type Html, Output Type Html, template from the File picker, data from Document Data File.

4. Convert HTML to PDF

PDF4me module. File set to the Generate module, Layout Portrait.

5. Upload a File

Dropbox module. Folder /pdf4meoutput, from the Convert module.

The short version

Two Dropbox Download a File modules fetch the HTML template and the JSON data. PDF4me Generate Document takes Template File Type Html, Output Type Html, its File picker set to the template download, Document DataType Json, and Document Data File mapped to the data download's Data. PDF4me Convert HTML to PDF then renders that HTML on Layout Portrait, and Dropbox Upload a File writes the PDF to /pdf4meoutput. Five modules, five operations, one PDF.

An HTML template can only produce HTML

Output Type on the Generate module offers nothing but Html when the template is HTML. That is why this scenario has a fourth module. Leave Output Type on Html and let Convert HTML to PDF produce the file you actually send.

Why-Based Q&A​

Why does two inputs not mean switching on Map?

It looks as though it should. Generate Document needs the template from module 1 and the data from module 2, and the File picker only takes one module. The answer is that the data is not part of the file group at all: Document Data File is its own field, mapped directly. So the picker handles the template, the data field handles the data, and the Map toggles you can see on screen belong to Template File Type, Output Type and Document DataType, all left off.

Why does the template's own file name matter?

PDF4me reads the template format from the extension on the name. Picking the template download in the File field carries invoice_template.html across with the bytes, which matches Template File Type Html. The two have to agree, which is the argument for letting the picker supply the name rather than typing one.

Why map Document Data File from the second download and not the first?

Because the two downloads look identical in the mapping panel, both offering File Name and Data. Mapping the template's Data into Document Data File feeds the layout to itself as data, and the run produces a document with every placeholder empty. Check the module number on the token before you save.

Why no Iterator in this scenario?

Generate Document is the singular module: one template, one data payload, one document back. The plural Generate Documents returns an array and does need an Iterator. Adding one here would sit between two modules that are already passing a single document.


What You'll Get​

Input: an HTML template and a JSON data file, both in cloud storage. This scenario reads /pdf4metest/GenerateDocumentFromHtml/invoice_template.html and /pdf4metest/GenerateDocumentFromHtml/invoice_data.json. Output: one PDF invoice in /pdf4meoutput, carrying the styling from the HTML.

The completed run​

The completed Make run showing two Download a File modules, PDF4me Generate Document, PDF4me Convert HTML to PDF and Dropbox Upload a File, each ticked green
Five modules, one operation each. Two PDF4me calls, because the generation and the rendering are separate steps.

What You Need​

Before you start
  • A Make account with a scenario you can edit.
  • A PDF4me API key. Open the PDF4me dashboard and create one.
  • A storage connection. This scenario uses Dropbox, authenticated by you.
  • An HTML template with placeholders written in mustache syntax. Self contained HTML renders most predictably, so inline the CSS.
  • A JSON data file whose structure matches what the template reads.

The Scenario at a Glance​

  1. Dropbox: Download a File, the HTML template.
  2. Dropbox: Download a File, the JSON data.
  3. PDF4me: Generate Document, template from the picker, data from its own field.
  4. PDF4me: Convert HTML to PDF, producing the PDF.
  5. Dropbox: Upload a File, to /pdf4meoutput.

Step 1: Dropbox, Download the HTML Template​

Flow so far: Download a File.

  1. Create a new scenario and click the first + on the canvas.
  2. Search Dropbox and pick Download a File.
  3. Configure:
    • Way of selecting files: Select a file
    • File: /pdf4metest/GenerateDocumentFromHtml/invoice_template.html

Template download configuration​

The Dropbox Download a File module reading invoice_template.html from the GenerateDocumentFromHtml folder
Module 1 is the layout. Its File Name and Data both get mapped in step 3.

Step 2: Dropbox, Download the JSON Data​

Flow so far: Download a File, Download a File.

  1. Add a second Dropbox: Download a File after the first. The scenario stays one straight chain.
  2. Configure:
    • Way of selecting files: Select a file
    • File: /pdf4metest/GenerateDocumentFromHtml/invoice_data.json

Data download configuration​

The second Dropbox Download a File module reading invoice_data.json
Module 2 is the values. Only its Data output is mapped, into Document Data File.

The data for this template is shaped around a Documents array, with a header, a body holding the invoice, biller and recipient blocks and a repeating Product array, and a footer. Abridged below to one line item, with the invoice instructions field and the fax and web entries removed, and the sample addresses replaced:

{
"Documents": [
{
"header": { "docType": "Original Copy" },
"body": {
"Column1": "Quantity",
"Column2": "Description",
"Column3": "Unit Price",
"Column4": "Total",
"Invoice": {
"number": 14957,
"date": "25-02-2022",
"subTotal": 200150,
"tax": "18%",
"dueDate": "25-03-2022",
"shipping": "200"
},
"Biller": {
"phone": "989797",
"email": "[email protected]",
"address": { "company": "Organization 1", "street": "Street 1", "city": "City 1", "zip": "123456" }
},
"Recepient": {
"name": "recepeint 1",
"address": { "street": "testveien 3", "city": "City 1", "zipcode": "0555", "country": "Country 1" }
},
"Product": [
{ "quantity": 1, "description": "item 1", "unitPrice": 45, "totalPrice": 867 }
]
},
"footer": { "phone": "phone123", "email": "[email protected]" }
}
]
}

Step 3: PDF4me, Generate Document​

Flow so far: Download a File, Download a File, Generate Document.

Two upstream modules feed this one, and they arrive through different fields: the template through the File picker, the data through Document Data File.

  1. Add PDF4me: Generate Document.
  2. Connection: click Add and paste your PDF4me API key.
  3. Configure:
    • Template File Type: Html
    • Output Type: Html
    • File: choose Dropbox - Download a File, the template download
    • Document DataType: Json
    • Document Data File: map Data from the data download
    • Document Data Text: leave empty

Generate Document configuration, upper half​

The PDF4me Generate Document module, upper half, showing Template File Type Html and Output Type Html
Template File Type and Output Type both read Html. With an HTML template, Output Type offers nothing else.

Generate Document configuration, lower half​

The lower half of the same module showing Document DataType Json, Document Data Text empty and Document Data File mapped to Data from module 2
Document Data File maps module 2's Data. The module number on that token is the thing to check twice.
FieldComes fromWhy
Filethe template download, via the radio pickerCarries invoice_template.html and its bytes together
Document Data FileData of the data download, mappedThe values, as binary, in a field of its own
Document Data TextnothingThe alternative to the file, not a companion
Template File Typeliteral HtmlDeclares what the template is
Output Typeliteral HtmlThe only value an HTML template allows
Document DataTypeliteral JsonDeclares what the data is

Step 4: PDF4me, Convert HTML to PDF​

Flow so far: Download a File, Download a File, Generate Document, Convert HTML to PDF.

Only one module needs to feed this one. The File list still shows both Dropbox downloads and Map alongside Generate Document, so pick deliberately.

  1. Add PDF4me: Convert HTML to PDF.
  2. Configure:
    • File: choose PDF4me - Generate Document
    • Layout: Portrait

Convert HTML to PDF configuration​

The PDF4me Convert HTML to PDF module with File set to PDF4me Generate Document and Layout set to Portrait
The generated HTML goes straight into the renderer. Nothing touches storage in between.

Step 5: Dropbox, Upload a File​

Flow so far: Download a File, Download a File, Generate Document, Convert HTML to PDF, Upload a File.

  1. Add Dropbox: Upload a File.
  2. Configure:
    • Folder: /pdf4meoutput
    • File: choose PDF4me - Convert HTML to PDF
    • Leave Show advanced settings off. Overwrite an existing file sits behind it and stays at its default, so a second run does not replace the first file.

Upload a File configuration​

The Dropbox Upload a File module writing the rendered PDF invoice into the pdf4meoutput folder
File points at the Convert module, not at Generate Document, so the name already carries .pdf.

Dropbox stores whatever file it is handed, so a token pointing at module 3 files the intermediate HTML instead. Check that the token in File names module 4.


Run the Scenario and Verify​

Press Run once, then open the PDF and read it against the JSON.

What did you actually build?

A scenario that merges a JSON payload into an HTML invoice layout, renders the result as a PDF, and files it. Five modules, five operations per run. Check that every placeholder is filled and that the styling survived the render, because an external stylesheet the renderer could not reach produces a correct but unstyled invoice.


Common Variations You Can Add Without Rebuilding​

Generate several invoices at once

Generate Documents takes a data file holding many records and returns an array, which then needs an Iterator.

Use a Word template instead

Generate Document Using Template works from a stored .docx and skips the rendering step.

Keep the HTML as well

Add a second upload mapped to module 3, so the scenario files both the HTML and the PDF.

Email it

Replace module 5 with a mail module and the invoice goes out as an attachment instead of into storage.


Common Questions​

How do you create an invoice template in HTML?​

Build the layout in HTML and CSS as you would a web page, then put a mustache placeholder wherever a value belongs. Inline the CSS so the renderer does not have to fetch anything, and keep the structure of your JSON in mind as you name the fields.

How do you make an invoice bill in HTML automatically?​

Store the layout and the data separately, then let PDF4me merge them. Generate Document produces the filled HTML and Convert HTML to PDF turns it into the file you send.

Why use an HTML template rather than Word?​

Because the design already exists. A billing page or a web receipt that was built in HTML can be reused as the invoice layout without redrawing it in a word processor, and CSS gives finer control over spacing and type than a .docx does.

When should you use a Word template instead?​

When the people who maintain the layout work in Word, or when the output needs to stay editable as a document. The Word route also skips a module, because a .docx template can produce a PDF directly.

How do you generate invoices for your business from this?​

Replace the fixed JSON path with whatever holds your billing data, a Make data store, a database module, or a webhook from your billing system, and leave the rest of the scenario as it is. The template and the rendering do not change.


Troubleshooting​

Every placeholder in the output is empty

Document Data File is mapped to the template download instead of the data download. The two look identical in the mapping panel, so check the module number on the token.

Output Type will not let you pick Pdf

That is correct behaviour for an HTML template. Leave it on Html and add Convert HTML to PDF as the next module.

The PDF is unstyled

The template links a stylesheet the renderer could not fetch. Inline the CSS and embed images as data: URIs so the template is self contained.

An HTML file lands in the output folder instead of a PDF

Module 5 is mapped to Generate Document rather than to Convert HTML to PDF, and the scenario goes green either way. Check that the token in its File field names module 4.


Next Steps​

Point modules 1 and 2 at your own template and data, run it once against a single record, and open the PDF before you wire anything that produces invoices in bulk.