pdf-mcp Documentation
Browse documentation
Markdown

n8n integration

Call pdf-mcp from an n8n workflow with an HTTP Request node

On this page

Call pdf-mcp from an n8n workflow with an HTTP Request node. The same setup works for invoices, reports, certificates, and other HTML-based documents.

What n8n does

n8n connects apps and services in automated workflows. A workflow can call pdf-mcp to:

  • 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

Before you start

  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: Add credentials

  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 the 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 settings

Basic settings

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

Headers

HeaderValue
Content-Typeapplication/json

JSON body

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

Node JSON to import

Paste this JSON into n8n to create a configured HTTP Request node:

HTML to PDF node

JSON
{
  "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 it:

  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 example

JSON
{
  "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
}

The expression reads invoice_number, customer_name, item_description, and amount from the input data.


Workflow examples

1. Form submission to PDF

Trigger: Webhook or Form node receiving submissions

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

2. Scheduled report

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

3. Order confirmation invoice

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

4. Certificate

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

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 request and response details.


cURL examples

Test the API directly before configuring n8n:

Basic HTML to PDF request

Shell
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

Shell
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

Shell
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 clients

For an MCP client, enter the hosted Streamable HTTP URL directly. There is no pdf-mcp package or local server to install. See the verified MCP client setup guide.


Handle the response

The HTTP Request node returns the PDF as binary data. Pass that output to the next node that needs the file.

Save to a file

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

Send by 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 it from a webhook

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


Error handling

Add an Error Trigger node to route failed requests.

Common status codes

CodeDescriptionSolution
200SuccessPDF generated successfully
401UnauthorizedCheck your API key in credentials
402Payment RequiredAdd credits to the account
403ForbiddenVerify API key permissions
400Bad RequestCheck your request body format
500Server ErrorReview HTML syntax or contact support

Error-handling workflow

Plain text
[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

Implementation notes

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

n8n requests use the same credits as direct API requests:

  • HTML to PDF: 1 credit for the first page, plus 0.01 per additional page
  • Render template: 1 credit for the first page, plus 0.01 per additional page
  • PDF to image: 1 credit for the first page, plus 0.01 per additional page
  • AI template generation: 1 credit per successful message
  • Other PDF utilities, including form operations and file search: 0.01 credits per request
  • Direct file, template, asset, and theme management: free

The dashboard shows current usage.