
Automation platforms like n8n are becoming increasingly popular for building internal tools, AI workflows, and business automations without writing full backend applications.
In this tutorial, we will build a complete automated workflow that:
The final workflow will look like this:
Form Trigger
↓
Generate HTML Template
↓
Convert HTML to PDF
↓
Send Email with PDF Attachment
At the end of this article, you will also be able to download and import the complete n8n workflow template.
In this example:
Create a new workflow in n8n and add "Form Trigger" node.
This node creates a public form where users can submit invoice data.
Add fields:
| Field | Type |
|---|---|
| customerName | Text |
| invoiceNumber | Text |
| total | Text |
Add a "code" node.
This node will dynamically generate invoice HTML.
const clientName = $json.clientName;
const clientEmail = $json.clientEmail;
const invoiceNumber = $json.invoiceNumber;
const total = $json.total;
const html = `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
body {
font-family: Arial, sans-serif;
padding: 40px;
color: #333;
}
.invoice {
max-width: 700px;
margin: 0 auto;
border: 1px solid #ddd;
padding: 30px;
}
h1 {
color: #222;
}
.total {
margin-top: 30px;
font-size: 24px;
font-weight: bold;
}
</style>
</head>
<body>
<div class="invoice">
<h1>Invoice</h1>
<p><strong>Invoice Number:</strong> ${invoiceNumber}</p>
<p><strong>Customer:</strong> ${clientName}</p>
<div class="total">
Total: €${total}
</div>
</div>
</body>
</html>`;
return {
json: {
html,
recipient: clientEmail,
name: clientName
}
};
Now add an "HTTP Request" node.
Configuration:
| Setting | Value |
|---|---|
| Method | POST |
| Authentication | Generic Credential Type |
| Generic Auth Type | Header Auth |
| Header Auth | Name: x-api-key, Value: your-api-key-*** |
| URL | https://api.html2pdf.app/v1/generate |
| Send Body | On |
| Specify Body | Using Fields Below |
| Body Parameters | html: {{$json.html}} |
| Response Format | File |
| Put Output in Field | data |
By setting "Header Auth" click edit on "Header Auth account" and set values accordingly to the image below. You will need an HTML2PDF.app API key — you can register and get a free API key here:

We recommend storing your HTML2PDF.app API key securely using the Credentials system instead of hardcoding it into the workflow.
Add a "Send Email" node.
In this tutorial we use SMTP credentials with Mailgun.
Configuration example:
| Field | Value |
|---|---|
| From Email | [email protected] |
| To Email | {{ $json.recipient }} |
| Subject | Your Invoice |
| Email Format | HTML |
| Attachments | data |
Example of HTML email message:
Hello {{ $json.name }},
<br><br>
Please find your invoice attached.
<br><br>
Thank you.
When you finish all these steps, the result of your workflow should be similar to this (nodes can have custom names for clarity):

After activating the workflow:
Combining n8n with HTML2PDF.app allows you to build powerful document automation workflows in minutes.
Instead of manually generating invoices, reports, or PDFs, you can fully automate the entire process:
without building a custom backend service.
Download the ready-to-use n8n workflow template and import it directly into your n8n instance. After importing, configure your own HTML2PDF.app API credentials and email provider credentials.
Download Template