
Automating document creation is a powerful way to streamline business operations and increase efficiency. One particularly valuable use case is generating PDF contracts dynamically based on input data—such as customer details and service terms. If you’re looking for a low-code, open-source solution to do this, n8n is a fantastic choice. In this article, we’ll walk you through how to build a PDF contract generator using n8n, and even provide you with a free template to get started immediately.
Why Use n8n for PDF Generation?
n8n is an open-source workflow automation tool that allows users to integrate various services and automate complex processes. With its intuitive interface and powerful node-based logic, it’s ideal for tasks like dynamic document generation.
Unlike paid platforms with restrictive APIs or license costs, n8n offers you flexibility and control over your workflows—without sacrificing long-term scalability or budget.

What You’ll Need
Before diving into the workflow creation, make sure you have the following:
- An instance of n8n (either locally or cloud-hosted)
- Basic knowledge of n8n workflow nodes
- Access to a web template engine (like Handlebars)
- A method for converting HTML to PDF – often done using an API like PDFMonkey, PDFShift, or custom scripts
Step-by-Step: Building the PDF Contract Generator
This process involves configuring a series of nodes in n8n to accept contract inputs, format them with HTML, convert to PDF, and then optionally send or store the file.
1. Define the Input Trigger
Choose how your workflow will start. This could be via a webhook (for integration with forms), a scheduled time (for batch generation), or even a manual trigger within n8n. For most use cases, a Webhook node is the most versatile option.
2. Prepare Your Dynamic Data
Next, use a Set or Code node to capture key variables:
- Client name
- Service description
- Hourly rate or project cost
- Start and end dates
You can either set these values directly or map them from an incoming payload.
3. Format the HTML Contract
Use a Function or HTML node to generate the contract body using dynamic inputs. A templating engine like Handlebars is greatly helpful at this stage to maintain readability and scalability.
Example HTML template:
<html> <body> <h1>Contract Agreement</h1> <p>This contract is between <strong>{{clientName}}</strong> and our company.</p> <p>Service Description: {{serviceDesc}}</p> <p>Start Date: {{startDate}} – End Date: {{endDate}}</p> <p>Total Cost: ${{cost}}</p> </body> </html>
4. Convert HTML to PDF
Depending on your stack, you can invoke an external API or Docker service to convert the HTML to a PDF. Use an HTTP Request node to call the PDF generation service. Make sure to handle API keys securely using credentials inside n8n.

5. Output: Send or Store the Contract
Finally, decide what to do with the generated PDF. Common options include:
- Send via email using an Email node
- Upload to cloud storage like Google Drive or S3
- Send back in API response (for webhook-based workflows)
Implementing proper error-handling paths within these output stages ensures users get notified if anything fails in the workflow.
Download Your Free n8n Template
To make your journey even easier, we’ve prepared a ready-to-use workflow file you can import directly into n8n. This includes nodes configured for:
- Webhook input
- Dynamic HTML generation
- PDF conversion via API
- Email delivery
Click here to download the free template: Download Contract Generator Workflow
Security & Best Practices
When sending or storing PDFs that contain sensitive information, always follow industry best practices. This includes:
- Use HTTPS for API calls
- Encrypt sensitive data
- Restrict access to generated files
Properly handle errors and user validations to avoid edge case failures or insecure file access.
Final Thoughts
Creating a PDF contract generator in n8n isn’t just feasible—it’s practical and powerful. With the flexibility to integrate third-party services and the control to build fully customizable templates, you can automate your contract management workflows affordably and efficiently. Download the free template today and start saving hours of manual work from your operations.