# HTML to PDF in n8n

Convert HTML or URLs to PDF in n8n workflows with the HTTP Request node and the html-pdf.com API. You get a binary PDF file or a 24h download link.

**Quick answer.** Add an **HTTP Request** node with these settings and run it. You get back a PDF download link.

- **Method:** `POST`
- **URL:** `https://html-pdf.com/v1/pdf`
- **Header:** `Authorization` = `Bearer hp_live_...`
- **Body (JSON):** `{"html": "<h1>Hello</h1>", "response": "url"}`

## Get an API key

This step gives you a key. Get one by email at https://html-pdf.com/login, or with one call:

```bash
curl -X POST https://html-pdf.com/v1/signup \
  -H "Content-Type: application/json" \
  -d '{"email": "you@example.com"}'
```

Then open the link we email you to confirm your address. That adds the 100 free credits. 1 credit = 1 PDF page, and no card is needed.

## Connect

Here is the full node setup. Add an **HTTP Request** node:

- **Method:** `POST`
- **URL:** `https://html-pdf.com/v1/pdf`
- **Authentication:** Generic Credential Type → **Header Auth**. Set Name to `Authorization` and Value to `Bearer hp_live_...`.
- **Send Body:** on. **Body Content Type:** JSON. **Specify Body:** Using JSON.

```json
{
  "html": "<h1>Order {{ $json.orderId }}</h1><p>Total: {{ $json.total }}</p>",
  "format": "A4",
  "margin": "15mm",
  "filename": "order.pdf"
}
```

Your HTML may come from an earlier node and contain quotes or line breaks. In that case, build the body with an expression so it is escaped correctly.

```
{{ JSON.stringify({ html: $json.html, format: "A4", margin: "15mm" }) }}
```

**Get the PDF as a file:** under **Options → Response**, set **Response Format** to **File**. The PDF lands in the item's binary property `data`, ready for Gmail, Google Drive, S3 or Slack nodes.

**Or get a link:** add `"response": "url"` to the body and keep Response Format as JSON. You get `{"url": "...", "pages": 1, "credits_remaining": 99, ...}`. The link is valid for 24 hours.

For a web page, send `{"url": "https://example.com"}` instead of `html`.

## Try it

These two workflows show common ways to use the node.

- Webhook → Code (build HTML invoice) → HTTP Request (PDF, Response Format File) → Gmail (attach `data`).
- Schedule → HTTP Request (`{"url": "https://your-dashboard.example.com/report", "media": "screen"}`) → Google Drive upload.

## Tips

These settings help with layout, cost and monitoring.

- **Page breaks:** put `<div style="break-before: page"></div>` between sections in your HTML.
- **Page numbers:** add `"footer_html": "<div style='font-size:9px;width:100%;text-align:center'><span class='pageNumber'></span> / <span class='totalPages'></span></div>"` and a margin.
- **Set `max_pages`** so bad input never burns credits. Renders over the limit fail and cost nothing.
- **Monitoring:** turn on **Include Response Headers and Status** to read `X-Pages` and `X-Credits-Remaining`.

## Troubleshooting

Most problems come from the response format or broken JSON.

- **PDF shows up as garbled text:** Response Format is still JSON or Autodetect. Set it to File.
- **400 `invalid_json`:** your HTML broke the JSON. Use the `JSON.stringify` expression above.
- **403 `email_not_confirmed`:** the email behind the key isn't confirmed yet. Click the link we emailed you (it adds the 100 free credits), then run the workflow again.
- **402 `insufficient_credits`:** top up at https://html-pdf.com/login. Credits never expire. Turn on **Settings → On Error → Continue** if you want to handle this in the workflow.

## FAQ

### Is there a free HTML to PDF node for n8n?

You can use the built-in HTTP Request node with html-pdf.com. New accounts get 100 free credits once, with no card, and each credit is one PDF page.

### How do I get the PDF as a binary file in n8n?

Under **Options → Response**, set **Response Format** to **File**. The PDF is stored in the binary property `data`, which you can attach in Gmail or upload to Google Drive or S3.

### Can I convert a URL to PDF in n8n?

Yes. Send `{"url": "https://example.com"}` in the body instead of `html`. The page must be publicly reachable.

### Do credits expire?

No. Purchased credits never expire, and failed renders cost nothing. Packs start at $10 for 1,000 credits.

Full reference: [API docs](https://html-pdf.com/docs) · [MCP server](https://html-pdf.com/mcp)
