HTML to PDF

The HTML to PDF node allows you to generate PDF files from HTML using n8n. Unlike raw text-based PDFs, using HTML and CSS allows for beautifully formatted documents, including tables, colors, and branding.
HTML to PDF node
HTML to PDF node

Generate a PDF from HTML

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. Open a n8n workflow and add a Webhook node.
  2. Set the method to POST to accept dynamic HTML data.
  3. Copy the Webhook URL to test sending requests.
    Webhook URL
    Webhook URL
  4. Add the HTML to PDF (customJS) node to the workflow.
  5. In the HTML Input field, insert your dynamic HTML content. Example:
    <h1>Invoice</h1>
    <p>Customer: {{ $json.customer }}</p>
    <p>Amount: ${{ $json.amount }}</p>
    
  6. Connect the output of HTML to PDF (customJS) to the Respond to Webhook node.
    Webhook Flow
    Webhook Flow
  7. Configure it to return the generated binary PDF file.
  8. Test the webhook with a sample request to receive the PDF.

n8n workflow template: Convert HTML to PDF and return via Webhook

This workflow template:

  1. Accepts HTML input via a POST request.
  2. Converts HTML to PDF using CustomJS's PDF toolkit.
  3. Sends the PDF back to the original webhook requester.
Use this template
n8n pdf node
n8n pdf node

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.