How to Generate PDF Invoices From an HTML Template (Node.js, Python, C#)
Invoicing can be a tedious and time-consuming process, especially if you’re doing it manually. But what if there was a way to automate the process and create PDF invoices from an HTML template?
Well, there is!
With APITemplate.io’s invoice generator API, you can create PDF invoices from an HTML template, automate receipts and financial reports, and streamline invoice creation using your favorite programming language.

In this tutorial, we are going to generate PDF documents from HTML with APITemplate.io PDF generation API and programming languages like Python, C#, and Node.js.
Why use HTML to Create Invoices?
If you’re a web developer and asked to create invoices, what language do you choose? If you’re like most web developers, the answer is HTML.
HTML is the markup language of the web. It’s what tells a web browser how to display the content of a web page. All major web browsers support HTML, and it’s the common language that they use to display web pages.
HTML is an open standard, which means that anyone can use it to create a website. There are no licensing fees or other restrictions on using HTML.
if you need help learning HTML, there’s a wide range of available resources on the Internet. A website like W3Schools is a great place for beginners. It offers clear and concise tutorials that explain the basics of HTML and how to use it to create web pages.
In other words, HTML is the perfect choice for creating invoices.
What is APITemplate.io and the PDF generation API?
If you’re looking for an easy way to generate PDF documents and images, APITemplate.io is the perfect solution. With APITemplate.io, we can quickly create PDFs and images from reusable templates that can be automated with Zapier, Airtable, Make.com, n8n, UiPath, or REST API.
When it comes to PDF generation, we support technologies like HTML, custom CSS, Javascript, and Jinja2 templating language for you to create dynamic PDF content. We also offer a WYSIWYG editor for those who prefer a more visual approach to template creation.
Click here to learn more about the PDF generation API
The Steps to Generate PDF invoices from HTML
An invoice is a document that businesses send to their customers to request payment for goods or services. An invoice typically contains several important components, such as a description of the goods or services sold, the date of the transaction, the customer’s account information, and the amount due.
Now that we understand what an invoice is and the components that make up an invoice, let’s move on to automate PDF invoice creation with REST API.
The followings are the detailed steps to create PDF documents with APITemplate.io and generate PDFs with Node.js, Python, and C#.
Step 1: Getting Started with APITemplate.io
To get started, simply go to APITemplate.io and click on the Sign-Up button. After creating an account and logging in, you’ll be taken to your account dashboard.

After that, the first thing that you have to do is get the API key. To do that, simply click on the API Integration button on the navigation bar and then copy the API Key. We will use this API Key in our code later.

Step 2: Creating a Template
Now, it’s time to create a template for our PDF invoice. To do that, simply click on the Manage Templates button on the navigation bar and then click on the New PDF Template button.
Next, select a predefined template and give it a name. After that, click on the Create button to save the template.

Step 3: Editing HTML Template
Next, you can find the edit button on the right side of the template name on the Manage Templates page.

After clicking on the edit button, you’ll be redirected to the template editor. There are 4 tabs in the template editor: Template, JSON, CSS, and Settings.
Template Tab
The Template tab holds the invoice’s HTML. Replace its contents with this complete invoice, which keeps its styles in a <style> block so it works on its own:

<style>
body { font-family: sans-serif; font-size: 14px; }
table { width: 100%; border-collapse: collapse; margin-top: 24px; }
th, td { padding: 8px; border-bottom: 1px solid #ddd; }
.align-left { text-align: left; }
.align-center { text-align: center; }
.align-right { text-align: right; }
.total { text-align: right; font-weight: bold; margin-top: 16px; }
</style>
<h1>Invoice {{ invoice_no }}</h1>
<p>Date: {{ date }}<br>Bill to: {{ customer_name }}</p>
{% set ns = namespace(total=0) %}
<table>
<thead>
<tr>
<th class="align-left">Item</th>
<th class="align-center">Qty</th>
<th class="align-right">Unit price</th>
<th class="align-right">Amount</th>
</tr>
</thead>
<tbody>
{% for item in items %}
<tr>
<td class="align-left">{{ item.item_name }}</td>
<td class="align-center">{{ item.unit }}</td>
<td class="align-right">{{ "$%.2f" | format(item.unit_price) }}</td>
<td class="align-right">{{ "$%.2f" | format(item.unit_price * item.unit) }}</td>
</tr>
{% set ns.total = ns.total + item.unit_price * item.unit %}
{% endfor %}
</tbody>
</table>
<p class="total">Total: {{ "$%.2f" | format(ns.total) }}</p>The double curly braces and {% %} tags are Jinja2, the template language APITemplate.io uses:
{{ invoice_no }}prints a value from your data.{% for item in items %}repeats the table row once per line item."$%.2f" | format(...)formats a number as a price with two decimals.namespace(total=0)keeps a running total across the loop, so the invoice adds up its own lines.
Our docs explain loops, filters and the rest of the template language.
JSON Tab
The JSON tab holds sample data for the live preview. Paste the same data the code below sends:
{
"invoice_no": "INV-1001",
"date": "21/11/2026",
"customer_name": "Acme Corp",
"items": [
{ "item_name": "Design work", "unit": 10, "unit_price": 85 },
{ "item_name": "Hosting (12 months)", "unit": 1, "unit_price": 240 }
]
}CSS Tab
The CSS tab is another place for styles. The template above carries its own, so you can leave this tab as it is.

Settings Tab
In the Settings tab, you can change the HTML for your header and footer; see how to add a logo to your PDF header or footer. You can also change the paper size and orientation here.
Once you’re done, click on the Save button, and copy the template ID from the Manage Templates page. You’ll need it, and your API key from Step 1, in the code below.
Step 4: Create PDF Invoice
Now that the template is ready, each invoice is one API call: send the invoice data as JSON to POST /v2/create-pdf with your template ID, and the API returns a download_url for the finished PDF. Each example below then downloads the file and saves it as INV-1001.pdf.
We ran all three examples against a test server that checks the request the way the API does, and each saved a valid PDF.
Using Node.js
Node.js 18 and newer include fetch, so no packages are needed. Save this as invoice.mjs and run node invoice.mjs:
import { writeFile } from 'node:fs/promises';
const API_KEY = 'YOUR_API_KEY';
const TEMPLATE_ID = 'YOUR_TEMPLATE_ID';
// The data for one invoice. The keys match the variables in the template.
const invoice = {
invoice_no: 'INV-1001',
date: '21/11/2026',
customer_name: 'Acme Corp',
items: [
{ item_name: 'Design work', unit: 10, unit_price: 85 },
{ item_name: 'Hosting (12 months)', unit: 1, unit_price: 240 },
],
};
const res = await fetch(`https://rest.apitemplate.io/v2/create-pdf?template_id=${TEMPLATE_ID}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-API-KEY': API_KEY },
body: JSON.stringify(invoice),
});
const result = await res.json();
if (result.status !== 'success') throw new Error(`API error: ${JSON.stringify(result)}`);
// Download the finished invoice
const pdf = await fetch(result.download_url);
await writeFile(`${invoice.invoice_no}.pdf`, Buffer.from(await pdf.arrayBuffer()));
console.log(`Saved ${invoice.invoice_no}.pdf`);Using Python
Install the requests package (pip install requests), then run:
import requests
API_KEY = "YOUR_API_KEY"
TEMPLATE_ID = "YOUR_TEMPLATE_ID"
# The data for one invoice. The keys match the variables in the template.
invoice = {
"invoice_no": "INV-1001",
"date": "21/11/2026",
"customer_name": "Acme Corp",
"items": [
{"item_name": "Design work", "unit": 10, "unit_price": 85},
{"item_name": "Hosting (12 months)", "unit": 1, "unit_price": 240},
],
}
response = requests.post(
"https://rest.apitemplate.io/v2/create-pdf",
params={"template_id": TEMPLATE_ID},
headers={"X-API-KEY": API_KEY},
json=invoice,
)
response.raise_for_status()
result = response.json()
# Download the finished invoice
pdf = requests.get(result["download_url"])
with open(f"{invoice['invoice_no']}.pdf", "wb") as f:
f.write(pdf.content)
print(f"Saved {invoice['invoice_no']}.pdf")raise_for_status() stops the script with a clear error if the API rejects the request, for example because of a wrong API key or template ID.
Using C#
This is a complete .NET 6 or newer console app (dotnet new console, then replace Program.cs):
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
const string ApiKey = "YOUR_API_KEY";
const string TemplateId = "YOUR_TEMPLATE_ID";
// The data for one invoice. The property names match the variables in the template.
var invoice = new
{
invoice_no = "INV-1001",
date = "21/11/2026",
customer_name = "Acme Corp",
items = new[]
{
new { item_name = "Design work", unit = 10, unit_price = 85m },
new { item_name = "Hosting (12 months)", unit = 1, unit_price = 240m },
},
};
using var http = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post,
$"https://rest.apitemplate.io/v2/create-pdf?template_id={TemplateId}")
{
// StringContent sends a Content-Length header; JsonContent would stream the body chunked
Content = new StringContent(JsonSerializer.Serialize(invoice), Encoding.UTF8, "application/json"),
};
request.Headers.Add("X-API-KEY", ApiKey);
var response = await http.SendAsync(request);
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadFromJsonAsync<ApiResult>();
// Download the finished invoice
var pdf = await http.GetByteArrayAsync(result!.download_url);
await File.WriteAllBytesAsync($"{invoice.invoice_no}.pdf", pdf);
Console.WriteLine($"Saved {invoice.invoice_no}.pdf");
record ApiResult(string status, string download_url);The API key goes on the create request only, so it isn’t sent along when the PDF is downloaded.
Step 5: Generate Invoices in Bulk
To create invoices for many orders, call the API once per invoice with that order’s data, in a loop or from a queue. The template stays the same; only the JSON changes. To render the same kind of template in your own code instead, see how to generate a PDF from JSON with Node.js or Python.
For large batches, add async=1 and a webhook_url to the request. The API then answers straight away and calls your URL when each PDF is ready, instead of keeping the connection open. Async generation and webhooks are on paid plans; see the API reference for the parameters.
If you’d rather not write code, the same template works from Zapier, Make.com or Airtable. The invoice automation page shows those workflows.
Conclusion
In conclusion, automating invoice creation by converting HTML templates into PDFs can significantly streamline your invoicing process. APITemplate.io offers a user-friendly platform that supports various programming languages, including Python, C#, and Node.js, to facilitate this automation.
By leveraging APITemplate.io’s features, such as the WYSIWYG editor and support for custom CSS and JavaScript, you can create dynamic and professional invoices with ease. This approach not only saves time but also reduces the potential for errors associated with manual invoicing.
Ready to enhance your invoicing process? Sign up for APITemplate.io today and experience seamless PDF generation from HTML templates.


