Integrate pdf-mcp with n8n to automate PDF generation in your workflows. This guide covers setting up HTTP Request nodes to generate invoices, reports, certificates, and any HTML-based documents.

What is n8n?

n8n is a powerful workflow automation platform that connects apps and services. With pdf-mcp integration, you can:

  • Generate PDFs from form submissions or webhooks
  • Create invoices automatically when orders are placed
  • Produce reports on a schedule
  • Convert HTML templates to PDFs in any workflow

Prerequisites

Before you begin:

  1. An n8n instance (cloud or self-hosted)
  2. A pdf-mcp account with an API key (Get your API key)
  3. Basic familiarity with n8n workflows

Quick Setup

Step 1: Create HTTP Header Auth Credential

  1. In n8n, go to Credentials in the left sidebar
  2. Click Add Credential
  3. Search for and select Header Auth
  4. Configure the credential:
    • Name: pdf-mcp API
    • Name: Authorization
    • Value: Bearer YOUR_API_KEY
  5. Click Save

Replace YOUR_API_KEY with your actual API key from the dashboard.

Step 2: Add HTTP Request Node

  1. Add an HTTP Request node to your workflow
  2. Configure it using the settings below or import the ready-to-use JSON

HTTP Request Node Configuration

Basic Settings

SettingValue
MethodPOST
URLhttps://api.pdf-mcp.io/htmlToPdf
AuthenticationHeader Auth
Credentialpdf-mcp API (created above)

Headers

HeaderValue
Content-Typeapplication/json

Body (JSON)

{
  "html": "<h1>Hello from n8n!</h1><p>This PDF was generated automatically.</p>",
  "filename": "document.pdf"
}

Ready-to-Import Node JSON

Copy and paste this JSON directly into n8n to create a pre-configured HTTP Request node:

HTML to PDF Node

{
  "parameters": {
    "method": "POST",
    "url": "https://api.pdf-mcp.io/htmlToPdf",
    "authentication": "genericCredentialType",
    "genericAuthType": "httpHeaderAuth",
    "sendHeaders": true,
    "headerParameters": {
      "parameters": [
        {
          "name": "Content-Type",
          "value": "application/json"
        }
      ]
    },
    "sendBody": true,
    "bodyParameters": {
      "parameters": [
        {
          "name": "html",
          "value": "={{ $json.html }}"
        },
        {
          "name": "filename",
          "value": "={{ $json.filename || 'document.pdf' }}"
        }
      ]
    },
    "options": {
      "response": {
        "response": {
          "responseFormat": "file"
        }
      }
    }
  },
  "name": "Generate PDF",
  "type": "n8n-nodes-base.httpRequest",
  "typeVersion": 4.2
}

To import:

  1. Copy the JSON above
  2. In your n8n workflow, press Ctrl+V (or Cmd+V on Mac)
  3. The node will be added to your canvas
  4. Connect your Header Auth credential

Dynamic HTML with Expressions

Use n8n expressions to generate dynamic content from previous nodes:

Invoice Generation Example

{
  "parameters": {
    "method": "POST",
    "url": "https://api.pdf-mcp.io/htmlToPdf",
    "authentication": "genericCredentialType",
    "genericAuthType": "httpHeaderAuth",
    "sendHeaders": true,
    "headerParameters": {
      "parameters": [
        {
          "name": "Content-Type",
          "value": "application/json"
        }
      ]
    },
    "sendBody": true,
    "specifyBody": "json",
    "jsonBody": "={{ JSON.stringify({ html: `<!DOCTYPE html><html><head><title>Invoice</title></head><body><h1>Invoice #${$json.invoice_number}</h1><p>Customer: ${$json.customer_name}</p><table style=\"width:100%; border-collapse:collapse;\"><tr style=\"background:#f0f0f0;\"><th style=\"border:1px solid #ddd; padding:8px;\">Item</th><th style=\"border:1px solid #ddd; padding:8px;\">Amount</th></tr><tr><td style=\"border:1px solid #ddd; padding:8px;\">${$json.item_description}</td><td style=\"border:1px solid #ddd; padding:8px;\">$${$json.amount}</td></tr></table><p><strong>Total: $${$json.amount}</strong></p></body></html>`, css: '@page { size: A4; margin: 2cm; }', filename: `invoice-${$json.invoice_number}.pdf` }) }}",
    "options": {
      "response": {
        "response": {
          "responseFormat": "file"
        }
      }
    }
  },
  "name": "Generate Invoice PDF",
  "type": "n8n-nodes-base.httpRequest",
  "typeVersion": 4.2
}

This expects input data with fields: invoice_number, customer_name, item_description, amount.


Common Use Cases

1. Form Submission to PDF

Trigger: Webhook or Form node receiving submissions

[Webhook] → [Generate PDF] → [Send Email with Attachment]

2. Scheduled Report Generation

[Schedule Trigger] → [Database Query] → [Generate PDF Report] → [Upload to S3/Google Drive]

3. Order Confirmation Invoice

[Stripe Webhook] → [Format Invoice Data] → [Generate Invoice PDF] → [Email to Customer]

4. Certificate Generation

[Google Sheets Trigger] → [Generate Certificate PDF] → [Send via Email]

All API Endpoints

Configure your HTTP Request node with these endpoints:

EndpointMethodDescription
/htmlToPdfPOSTConvert HTML to PDF
/textToPdfPOSTConvert plain text to PDF
/imageToPdfPOSTConvert images to PDF
/pdfToImagePOSTConvert PDF pages to images
/extractTextPOSTExtract text from PDF
/extractPagesPOSTExtract specific pages
/mergePdfsPOSTCombine multiple PDFs
/pageCountPOSTGet PDF page count

See the API Reference for detailed documentation on each endpoint.


cURL Examples

Test the API directly before configuring n8n:

Basic HTML to PDF

curl -X POST https://api.pdf-mcp.io/htmlToPdf \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1>Hello, World!</h1><p>Generated from n8n workflow.</p>"
  }' \
  --output document.pdf

Styled Invoice

curl -X POST https://api.pdf-mcp.io/htmlToPdf \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<!DOCTYPE html><html><head><title>Invoice</title></head><body><h1>Invoice #12345</h1><table><tr><th>Item</th><th>Amount</th></tr><tr><td>Service Fee</td><td>$99.00</td></tr></table><p>Total: $99.00</p></body></html>",
    "css": "@page { size: A4; margin: 2cm; } body { font-family: Arial, sans-serif; } table { width: 100%; border-collapse: collapse; } th, td { border: 1px solid #ddd; padding: 8px; }",
    "filename": "invoice-12345.pdf"
  }' \
  --output invoice-12345.pdf

Text to PDF

curl -X POST https://api.pdf-mcp.io/textToPdf \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Meeting Notes\n\nDate: January 15, 2025\n\n1. Project status review\n2. Timeline discussion\n3. Next steps",
    "filename": "meeting-notes.pdf"
  }' \
  --output meeting-notes.pdf

MCP Integration

Using AI Agents? MCPs (Model Context Protocols) provide plug-and-play connectivity with pdf-mcp. AI agents like Claude can generate PDFs natively using our MCP Server without any HTTP configuration.


Handling the Response

The HTTP Request node returns the PDF as binary data. Here’s how to work with it:

Save to File

Use a Write Binary File node after the HTTP Request to save locally.

Send via Email

Connect to an Email Send node (Gmail, SMTP, etc.) and attach the binary data.

Upload to Cloud Storage

Use nodes like AWS S3, Google Drive, or Dropbox to store generated PDFs.

Return via Webhook Response

If your workflow was triggered by a webhook, use Respond to Webhook to return the PDF.


Error Handling

Add an Error Trigger node to handle failures gracefully.

Common Status Codes

CodeDescriptionSolution
200SuccessPDF generated successfully
401UnauthorizedCheck your API key in credentials
403ForbiddenVerify API key permissions or credit balance
400Bad RequestCheck your request body format
500Server ErrorReview HTML syntax or contact support

Error Handling Workflow

[HTTP Request] → [IF Node (check status)] → [Success: Continue] or [Error: Send Alert]

Troubleshooting

PDF is empty or not generated

  • Verify your API key is correct and has credits
  • Check that the html field contains valid HTML
  • Test with a simple HTML string first

Authentication errors

  • Ensure the Header Auth credential has Authorization as the name
  • The value must be Bearer YOUR_API_KEY (with a space after Bearer)
  • API key should not include quotes

Binary data issues

  • Set Response Format to File in node options
  • Make sure downstream nodes expect binary data

n8n expression errors

  • Use the expression editor to validate expressions
  • Escape special characters in template literals
  • Test with hardcoded values first

Tips and Best Practices

Performance

  • Keep HTML simple for faster generation
  • Use inline CSS instead of external stylesheets
  • Batch operations when generating multiple PDFs

Reliability

  • Add retry logic for transient failures
  • Store generated PDFs in cloud storage for durability
  • Log workflow executions for debugging

Security

  • Never expose your API key in shared workflows
  • Use n8n credentials system for secure storage
  • Sanitize user input in HTML templates


Credit Usage

API calls from n8n workflows use the same credit system as direct API calls:

  • PDF generation: ~1 credit per page
  • Text extraction: ~1 credit per page processed
  • Page count: ~0.1 credits per request

Monitor your usage in the dashboard.