Integration-n8n - Work With PDF Toolkit Community Node-html-to-pdf

Introduction

n8n is a powerful workflow automation tool that allows users to integrate different services and automate complex processes. One of its many capabilities is generating PDF files from HTML content, which is particularly useful for invoices, reports, or any structured document output.

In this blog, we’ll explore how to use the PDF Toolkit's HTML to PDF node in n8n to create high-quality PDFs from dynamic HTML templates.


Why Convert HTML to PDF in n8n?

1. Automated PDF Generation

With n8n, you can automate document generation, eliminating manual processes and reducing errors.

2. Custom Styling with HTML & CSS

Unlike raw text-based PDFs, using HTML and CSS allows for beautifully formatted documents, including tables, colors, and branding.

3. Easy Integration with Other Nodes

You can connect the HTML to PDF node with APIs, databases, or webhooks to dynamically create PDFs from structured data.


How to Generate a PDF from HTML in n8n

Step 1: Set Up Your Webhook

The first step in your workflow is setting up a Webhook node that will receive incoming data (e.g., invoice details, reports, or dynamic content).

  1. -  Add a Webhook node.
  2. -  Set the method to POST to accept dynamic HTML data.
  3. -  Copy the Webhook URL to test sending requests.

Step 2: Add the HTML to PDF Node

Next, you’ll use the HTML to PDF node from the CustomJS PDF Toolkit.

  1. -  Add the HTML to PDF node.
  2. -  In the HTML Input field, insert your dynamic HTML content. Example:
    <h1>Invoice</h1>
    <p>Customer: {{ $json.customer }}</p>
    <p>Amount: ${{ $json.amount }}</p>
    
  3. -  Ensure that the node is connected to your Webhook so it receives the data.

Step 3: Return the Generated PDF

Finally, add a Respond to Webhook node to return the generated PDF as a downloadable file.

  1. -  Connect the output of HTML to PDF to the Respond to Webhook node.
  2. -  Configure it to return the generated binary PDF file.
  3. -  Test the webhook with a sample request to receive the PDF.

Example Use Case: Generating an Invoice PDF

Imagine you have an online store, and you need to generate invoices automatically whenever an order is placed. Here’s how n8n can handle it:

  1. -  The Webhook receives order details via API.
  2. -  The HTML template dynamically fills in the customer’s name, items, and total price.
  3. -  The HTML to PDF node converts this into a professional invoice.
  4. -  The PDF is returned or emailed to the customer.