Automating PDF Generation with n8n
n8n is a powerful workflow automation tool that allows you to connect docpenny to hundreds of other services without writing code. This guide will show you how to set up a robust workflow to generate and handle PDFs.
What do I need before starting?
- An n8n instance (cloud or self-hosted).
- A docpenny API Key.
- A Template ID.
1. Triggering the Generation
The first step is to send your data to docpenny using the HTTP Request node.
Configure the Node:
- Method:
POST - URL:
https://api.docpenny.com/api/jobs - Authentication:
Header Auth- Name:
x-api-key - Value: Your API Key
- Name:
- Send Body:
true - Body Content Type:
JSON - Specify Body:
Using Fields BeloworJSON- templateId: Your Template ID
- data: A JSONL string of your data (e.g.,
{"name": "Alice"})
How do I handle async job processing?
Since docpenny generates documents asynchronously to ensure reliability, you need to wait for the job to complete.
The “Wait & Check” Pattern:
- Wait Node: Add a
Waitnode after your request, set to wait for 5-10 seconds. - HTTP Request (Check Status):
- Method:
GET - URL:
https://api.docpenny.com/api/jobs/{{ $node["HTTP Request"].json["jobId"] }} - Authentication: Use the same Header Auth as before.
- Method:
- IF Node: Check if
{{ $node["Check Status"].json["status"] }}isall_tasks_downloaded,ready_full_zip, orready_partial_zip.- False: Loop back to the Wait node.
- True: Proceed to download.
How do I download the generated PDF?
Once the job is complete, use another HTTP Request node to download the ZIP file.
Configure the Node:
- Method:
GET- URL:
https://api.docpenny.com/api/download/zip/{{ $node["HTTP Request"].json["jobId"] }}
- URL:
- Response Format:
File
Note: The ZIP download is one-time only. After downloading, subsequent requests to the same URL will return a 404.
You can then pass this file to other nodes, such as Email (SendGrid/Gmail), Google Drive, or Slack.
Pro Tip: Using Webhooks
Instead of polling with Wait nodes, you can use n8n’s Webhook node as a “Wait for Webhook” trigger.
- In your initial
POST /jobsrequest, include awebhookUrlpointing to your n8n Webhook URL. - Your workflow will then be triggered automatically as soon as the PDF is ready, saving execution time and resources.
How do I secure webhook calls?
Security is critical when using public webhooks. docpenny signs every payload with an X-Webhook-Signature header.
Verifying in n8n:
You can use a Crypto node or a Code node to verify the signature:
Code Node: After the Webhook trigger, add a Code node.
Implementation:
const crypto = require('crypto'); const secret = 'your_webhook_secret'; const signature = $node["Webhook"].json.headers['x-webhook-signature']; const body = JSON.stringify($node["Webhook"].json.body); const hmac = crypto.createHmac('sha256', secret); const digest = 'sha256=' + hmac.update(body).digest('hex'); if (signature !== digest) { throw new Error('Invalid Webhook Signature'); } return $node["Webhook"].json;
Official Blueprint
To get started instantly, you can download our pre-built n8n blueprint:
Full n8n Workflow
A complete workflow including job submission, status checking, and result downloading.