Generate PDFs from HTML in n8n (Step-by-Step Tutorial)

If your workflow generates invoices, reports, contracts, certificates, or any document that starts as HTML, you’ll eventually need to convert it into a PDF.

In this tutorial, I’ll show you how to generate PDFs directly inside n8n using PDF API Hub.

:movie_camera: Video Tutorial: https://youtu.be/krTf17AeHOs?si=oPRPvCxVa4urtBB_


What You’ll Build

A simple n8n workflow that:

  1. Receives HTML content
  2. Sends it to PDF API Hub
  3. Generates a PDF
  4. Returns a downloadable PDF URL

Perfect for:

  • Invoice generation
  • Client reports
  • Certificates
  • Contracts
  • Purchase orders
  • Automated document workflows

Step 1: Create a New Workflow

Create a new workflow in n8n and add a Manual Trigger node.

This allows you to test the workflow quickly while building it.


Step 2: Add HTML Content

Add a Set node and create a field called:

{
  "html": "<html><body><h1>Hello n8n!</h1><p>This PDF was generated automatically.</p></body></html>"
}

You can replace this with dynamic data later from Google Sheets, Airtable, Forms, CRM systems, or databases.


Step 3: Add the PDF API Hub Node

Install the PDF API Hub integration from the n8n community nodes and add it to your workflow.

Configure:

Operation: Generate PDF

Map the HTML field from the previous node.

The API supports:

  • Raw HTML
  • CSS styling
  • Custom fonts
  • A4, Letter, Legal paper sizes
  • Landscape mode
  • Background printing
  • Dynamic placeholders
  • URL to PDF conversion

Step 4: Configure PDF Settings

Example configuration:

  • Paper Size: A4
  • Print Background: True
  • Margin: Medium
  • Output Format: URL

These settings produce a downloadable PDF link that can be used in later workflow steps.


Step 5: Execute the Workflow

Run the workflow.

The node returns:

{
  "success": true,
  "pdf_url": "https://..."
}

You now have a PDF that can be:

  • Emailed automatically
  • Uploaded to Google Drive
  • Saved to S3
  • Attached to CRM records
  • Sent through Slack or Teams
  • Archived for compliance

Example Use Cases

Invoice Automation

Stripe → n8n → HTML Invoice → PDF → Email Customer

Weekly Reports

Database → HTML Report → PDF → Send to Management

Certificates

Form Submission → Generate Certificate HTML → PDF → Email User

Contracts

CRM Deal Won → Contract Template → PDF → Send for Signature


Why Use HTML Instead of PDF Templates?

HTML is easier to:

  • Version control
  • Generate dynamically
  • Customize with CSS
  • Reuse across workflows
  • Preview in a browser before generating PDFs

This makes it ideal for automated document generation.


Watch the Full Tutorial

The complete walkthrough is available here:

If you’re building document automation workflows in n8n, this can save a significant amount of manual work and eliminate the need for custom PDF generation infrastructure.

Happy automating :rocket:

Sample Templates:

  1. Post Google News headlines to Instagram images with GPT-4o-mini, PDF API Hub and Google Sheets | n8n workflow template

  2. Automate vehicle insurance claim approvals with OpenAI, OCR and PDF API Hub | n8n workflow template

  3. Automatically sign PDFs from a watched Google Drive folder with PDF API Hub | n8n workflow template

1 Like