Webhook JSON to PDF, sent by email (n8n)

An n8n workflow that turns nested JSON from a webhook into a formatted PDF with WeasyPrint and emails it. Built from n8n's own nodes.

Last updated

Operations weasyprint_render (POST /v1/weasyprint/render)
Platforms n8n
Nodes Webhook, Code, HTTP Request, Gmail

A system posts JSON to a webhook, often nested: a customer with an address, a list of line items. This workflow turns that payload into a clean PDF and emails it to the address in the payload. A Code node builds the HTML, the WeasyPrint API renders it, and Gmail sends the PDF as an attachment.

The Code node reads only the fields you name, so fields the payload adds later cannot break the layout. Escape every value before it reaches the page. An order confirmation, for example, has a line-item table, a total and page numbers.

The steps

  1. Receive order JSON (Webhook, POST). It answers the caller at once; the PDF is made afterwards.
  2. Build HTML (Code). Picks the fields, escapes them and writes an A4 HTML page with a @page footer for page numbers.
  3. Render PDF (HTTP Request). POSTs {"html": ..., "filename": ...} to https://api.pagespool.com/v1/weasyprint/render and puts the PDF in the binary field data.
  4. Email the PDF (Gmail). Attaches data and sends it to customer.email.

Inline images and fonts as data: URIs, because remote URLs are rejected (how).

Set up the HTTP Request node

  • Method POST, URL https://api.pagespool.com/v1/weasyprint/render.
  • Authentication: Generic Credential Type, Header Auth, with the name X-API-Key and your key as the value.
  • Send Body: JSON, with html set to the Code node's output and a filename.
  • Options > Response > Response Format: File, Put Output in Field data.

Get your API key. Each render costs 1 credit, whatever its page count, and a failed render costs nothing.

FAQ

What happens when the JSON payload gains a new field?
Nothing breaks. The Code node reads only the fields it names and ignores the rest, so a new or renamed key cannot change the layout. To show a new field, add it to the Code node.
Does this work on n8n Cloud?
Yes. The workflow uses only nodes that ship with n8n: Webhook, Code, HTTP Request and Gmail. The HTTP Request node POSTs html and filename as JSON to /v1/weasyprint/render and keeps the response as a file.