Document generation options in n8n

Getting started with n8n

This article is dedicated to advanced features of our n8n integration. If you wish to learn how to generate your first Document using n8n, we have a dedicated guide you can read:

Generating your first Document with n8n

Payload Input Methods

The PDFMonkey node offers two ways to send data to your template:

Key-Value Pairs (Simple Mode)

This is the easiest way to send simple data structures. You can add fields one by one:

Key-Value Pairs mode in n8n

Each field has:

  • Key: The variable name in your template

  • Value: The data to send (can be static or dynamic from previous nodes)

JSON Format (Advanced Mode)

For complex data structures, nested objects, or arrays, use the JSON format:

JSON format in n8n

Example of a complex JSON payload:

JSON Payload
{
  "customer": {
    "name": "Acme Inc.",
    "email": "[email protected]",
    "address": {
      "street": "123 Main St",
      "city": "New York",
      "zip": "10001"
    }
  },
  "items": [
    {
      "product": "Widget",
      "quantity": 5,
      "price": 10.99
    },
    {
      "product": "Gadget",
      "quantity": 2,
      "price": 24.99
    }
  ],
  "total": 104.93
}

In your template, you can access nested data like this:

HTML

Working with n8n expressions

One of n8n's most powerful features is the ability to use expressions to reference data from previous nodes:

{{ $json.customerName }}              // Simple field
{{ $node["Webhook"].json["email"] }}  // From specific node
{{ $json.items.length }}              // Array length
{{ new Date().toISOString() }}        // Current date

You can use these expressions in:

  • Key-Value pair values

  • JSON payload (as string values)

  • Custom filename

  • Metadata

Custom Filename

You can specify a custom name for the generated PDF. This is useful when storing files in Google Drive, Dropbox, or other storage services.

In the PDFMonkey node options:

  1. Expand Additional Options

  2. Set Custom Filename

  3. Use a static name or n8n expressions:

Invoice-{{ $json.invoiceNumber }}.pdf
Report-{{ $now.format('YYYY-MM-DD') }}.pdf
{{ $json.customerName }}-Contract.pdf

Attaching metadata to your Documents

Metadata is additional information attached to a document that doesn't appear in the PDF itself. It's useful for:

  • Tracking document origin

  • Storing reference IDs

  • Filtering in webhooks

To add metadata:

  1. Expand Additional Options in the PDFMonkey node

  2. Set Metadata to Key-Value Pairs or JSON

  3. Add your metadata fields:

{
  "orderId": "ORD-12345",
  "customerEmail": "[email protected]",
  "environment": "production"
}

You can retrieve metadata later using the Get Document operation or in webhook triggers.

Metadata vs Payload

  • Payload: Data used to generate the PDF content

  • Metadata: Information attached to the document but not visible in the PDF

Wait for Document

By default, the Generate Document operation waits for the PDF to be fully generated before continuing.

Document generation time

Most documents generate in a few seconds. Complex documents with many pages, images, or JavaScript may take longer.

Using arrays and complex data

n8n makes it easy to work with arrays from previous nodes. Here's how to pass arrays to PDFMonkey:

Example: Google Sheets to Invoice

If you have line items in Google Sheets:

Google Sheets node output:

[
  { "product": "Widget", "qty": 5, "price": 10 },
  { "product": "Gadget", "qty": 2, "price": 25 }
]

In PDFMonkey node (JSON mode):

{
  "customerName": "{{ $json.customerName }}",
  "items": {{ $node["Google Sheets"].json }}
}

The array will be passed directly to your template where you can loop over it:

{% for item in items %}
  <tr>
    <td>{{item.product}}</td>
    <td>{{item.qty}}</td>
    <td>{{item.price}}€</td>
  </tr>
{% endfor %}

Handling multiple items (looping)

If your workflow processes multiple items (like multiple customers or orders), you can use n8n's Split In Batches node:

1. Get Data (returns 100 items)
2. Split In Batches (batch size: 1)
3. PDFMonkey - Generate Document (runs 100 times)
4. Store PDFs

Or use the Loop Over Items node for more control.

Error handling

Use n8n's error handling features to manage failures:

  1. Click on the PDFMonkey node

  2. Go to Settings tab

  3. Configure On Error:

    • Stop Workflow (default)

    • Continue With Last Successful Item

    • Continue Execution

For more robust error handling, add an IF node after PDFMonkey to check the status:

IF: {{ $json.status }} equals "success"
  → TRUE: Continue with PDF
  → FALSE: Send error notification
Reacting to generated documents in n8nOther operations (Get, Download, Delete)

Last updated

Was this helpful?