Workflows
Blocks
Actions
Generate Document

Generate Document Action Block

What it does: Automatically create professional documents (PDFs, Word files, etc.) from templates using your workflow data.

📄

In simple terms: Fill templates with data and generate formatted documents like invoices, contracts, reports, or certificates automatically.

When to Use This

Use the Generate Document action when you need to:

  • ✅ Create invoices from order data
  • ✅ Generate contracts with customer information
  • ✅ Produce reports with dynamic content
  • ✅ Make certificates with personalized names
  • ✅ Create proposals automatically
  • ✅ Generate custom letters or emails

Example: When an order is placed, automatically generate an invoice PDF with order details, customer info, and payment terms.

Features

  • Multiple Formats: PDF, DOCX, HTML, TXT
  • Template Engine: Use variables and logic in templates
  • Dynamic Content: Insert workflow data automatically
  • Formatting: Rich text, tables, images, styling
  • Conditional Content: Show/hide sections based on data
  • Loops: Repeat sections (like line items)
  • File Storage: Save to cloud or return URL
  • Custom Styling: Apply fonts, colors, layouts
  • Headers/Footers: Add consistent branding
  • Page Numbering: Automatic page numbers

Setup

1. Choose Output Format

PDF: Best for professional documents

Invoices
Contracts
Reports
Certificates

DOCX: Editable Word documents

Proposals
Templates for editing
Form letters

HTML: Web-ready format

Email templates
Web content
Dynamic pages

TXT: Plain text

Simple reports
Data exports
Log files

2. Create Your Template

Templates use Handlebars syntax for variables and logic.

Basic Variable Insertion:

Hello {{customerName}},
 
Your order #{{orderId}} has been confirmed.
Total: ${{orderTotal}}

Nested Variables:

{{customer.firstName}} {{customer.lastName}}
{{customer.address.street}}
{{customer.address.city}}, {{customer.address.state}}

Conditional Content:

{{#if isPremiumCustomer}}
Thank you for being a Premium member!
{{else}}
Consider upgrading to Premium for exclusive benefits.
{{/if}}

Loops (Repeating Content):

Order Items:
{{#each items}}
  - {{this.name}}: ${{this.price}} x {{this.quantity}} = ${{this.total}}
{{/each}}
 
Total: ${{orderTotal}}

Conditional Sections:

{{#if hasDiscount}}
Original Price: ${{originalPrice}}
Discount: -${{discountAmount}}
{{/if}}
Final Price: ${{finalPrice}}

Template Examples

Invoice Template

INVOICE
 
Invoice #: {{invoiceNumber}}
Date: {{invoiceDate}}
Due Date: {{dueDate}}
 
BILL TO:
{{customer.name}}
{{customer.address.street}}
{{customer.address.city}}, {{customer.address.state}} {{customer.address.zip}}
Email: {{customer.email}}
 
ITEMS:
{{#each items}}
{{this.description}}
Quantity: {{this.quantity}} x ${{this.unitPrice}} = ${{this.total}}
{{/each}}
 
Subtotal: ${{subtotal}}
{{#if tax}}
Tax ({{taxRate}}%): ${{tax}}
{{/if}}
{{#if discount}}
Discount: -${{discount}}
{{/if}}
 
TOTAL DUE: ${{total}}
 
Payment Terms: {{paymentTerms}}
{{#if notes}}
Notes: {{notes}}
{{/if}}

Certificate Template

CERTIFICATE OF COMPLETION
 
This certifies that
 
{{participantName}}
 
has successfully completed
 
{{courseName}}
 
on {{completionDate}}
 
Grade: {{grade}}
Certificate ID: {{certificateId}}
 
{{#if honors}}
WITH HONORS
{{/if}}
 
___________________________
Instructor: {{instructorName}}

Contract Template

SERVICE AGREEMENT
 
This agreement is entered into on {{contractDate}}
 
BETWEEN:
{{company.name}}
{{company.address}}
 
AND:
{{client.name}}
{{client.address}}
 
SERVICES:
{{#each services}}
{{@index}}. {{this.description}}
   Fee: ${{this.fee}}
{{/each}}
 
TERMS:
{{#each terms}}
- {{this}}
{{/each}}
 
Total Contract Value: ${{totalValue}}
Duration: {{duration}}
Start Date: {{startDate}}
End Date: {{endDate}}
 
{{#if cancellationPolicy}}
Cancellation Policy:
{{cancellationPolicy}}
{{/if}}
 
SIGNATURES:
___________________________    ___________________________
{{company.name}}               {{client.name}}
Date: _____                     Date: _____

Report Template

MONTHLY REPORT
{{reportMonth}} {{reportYear}}
 
SUMMARY:
Total Revenue: ${{metrics.revenue}}
Total Orders: {{metrics.orders}}
Average Order Value: ${{metrics.avgOrderValue}}
Customer Satisfaction: {{metrics.satisfaction}}%
 
TOP PRODUCTS:
{{#each topProducts}}
{{@index}}. {{this.name}} - {{this.unitsSold}} units sold
{{/each}}
 
GROWTH METRICS:
Revenue Growth: {{growth.revenue}}%
Customer Growth: {{growth.customers}}%
Order Volume Growth: {{growth.orders}}%
 
{{#if alerts}}
ALERTS:
{{#each alerts}}
- {{this.type}}: {{this.message}}
{{/each}}
{{/if}}
 
Generated: {{generatedDate}}

Advanced Features

Formatting

Bold and Italic (HTML mode):

<b>Bold text</b>
<i>Italic text</i>
<u>Underlined text</u>

Headers:

<h1>Main Title</h1>
<h2>Section Header</h2>
<h3>Subsection</h3>

Tables:

<table>
  <tr>
    <th>Item</th>
    <th>Quantity</th>
    <th>Price</th>
  </tr>
  {{#each items}}
  <tr>
    <td>{{this.name}}</td>
    <td>{{this.quantity}}</td>
    <td>${{this.price}}</td>
  </tr>
  {{/each}}
</table>

Images

Insert Images:

<img src="{{logoUrl}}" alt="Company Logo" width="200" />
<img src="{{product.imageUrl}}" alt="Product Photo" />

Custom Styling (HTML/PDF)

CSS Styles:

<style>
  body {
    font-family: Arial, sans-serif;
    margin: 40px;
  }
  .header {
    background-color: #007bff;
    color: white;
    padding: 20px;
  }
  .total {
    font-size: 24px;
    font-weight: bold;
    color: #28a745;
  }
</style>
 
<div class="header">
  <h1>{{documentTitle}}</h1>
</div>
 
<div class="total">
  Total: ${{total}}
</div>

Helper Functions

Date Formatting:

{{formatDate date "MMMM DD, YYYY"}}
{{formatDate timestamp "MM/DD/YYYY HH:mm"}}

Number Formatting:

{{formatNumber value decimals=2}}
{{formatCurrency amount currency="USD"}}

Math Operations:

{{add value1 value2}}
{{subtract total discount}}
{{multiply price quantity}}
{{divide total count}}

String Operations:

{{uppercase text}}
{{lowercase text}}
{{capitalize name}}
{{truncate description length=100}}

Configuration Options

Page Settings (PDF)

Page Size:

A4 (default)
Letter
Legal
A3
Custom

Orientation:

Portrait
Landscape

Margins:

Top: 20mm
Bottom: 20mm
Left: 20mm
Right: 20mm

Headers and Footers (PDF)

Header Template:

<div style="text-align: center; font-size: 10px;">
  {{company.name}} - {{documentType}}
</div>

Footer Template:

<div style="text-align: center; font-size: 10px;">
  Page <span class="pageNumber"></span> of <span class="totalPages"></span>
</div>

Output Settings

Filename: Generated file name

invoice-{{invoiceNumber}}.pdf
contract-{{client.name}}-{{date}}.docx
report-{{month}}-{{year}}.pdf

Storage: Where to save

Return URL (default)
Save to cloud storage
Send via email

Response Mapping

Map generation result to variables:

Available Values:

File URL → {{document.url}}
File Name → {{document.filename}}
File Size → {{document.size}}
Generated At → {{document.timestamp}}
Status → {{document.status}}

Common Use Cases

1. Automated Invoicing

Trigger: Order completed Generate Document: Invoice PDF

Template: Invoice template
Data:
  invoiceNumber: {{order.id}}
  customer: {{order.customer}}
  items: {{order.items}}
  total: {{order.total}}
Output: invoice-{{order.id}}.pdf

2. Certificate Generation

Trigger: Course completed Generate Document: Certificate

Template: Certificate template
Data:
  name: {{student.name}}
  course: {{course.title}}
  date: {{completion.date}}
  grade: {{student.grade}}
Output: certificate-{{student.id}}.pdf
Email to: {{student.email}}

3. Contract Creation

Trigger: Deal won Generate Document: Contract

Template: Service agreement
Data:
  client: {{deal.client}}
  services: {{deal.services}}
  terms: {{deal.terms}}
  value: {{deal.value}}
Output: contract-{{deal.id}}.docx

4. Monthly Reports

Trigger: Schedule (1st of month) Generate Document: Report

Template: Monthly report
Data:
  month: {{currentMonth}}
  metrics: {{fetchMetrics()}}
  topProducts: {{getTopProducts()}}
  growth: {{calculateGrowth()}}
Output: report-{{month}}-{{year}}.pdf
Email to: management@company.com

Best Practices

Template Design

  • ✅ Test templates with sample data first
  • ✅ Handle missing data gracefully
  • ✅ Use consistent formatting
  • ✅ Include all necessary information
  • ✅ Add branding elements (logo, colors)

Data Preparation

  • ✅ Validate data before generating
  • ✅ Format numbers and dates consistently
  • ✅ Handle null/undefined values
  • ✅ Calculate totals beforehand
  • ✅ Sanitize user input

Performance

  • ✅ Optimize images before inclusion
  • ✅ Keep templates reasonably sized
  • ✅ Cache templates when possible
  • ✅ Generate documents asynchronously for large files
  • ✅ Use appropriate formats for use case

Quality

  • ✅ Preview documents before deployment
  • ✅ Test with edge cases
  • ✅ Verify calculations
  • ✅ Check formatting on different devices
  • ✅ Validate against requirements

Troubleshooting

Template Errors

Check:

  • Handlebars syntax is correct
  • Variable names match workflow data
  • Closing tags are present
  • No typos in variable names

Missing Data

Solutions:

  • Use default values: {{value or "N/A"}}
  • Add conditionals: {{#if value}}{{value}}{{/if}}
  • Validate data before generation
  • Log missing fields for debugging

Formatting Issues

Fix:

  • Check HTML/CSS syntax
  • Test in different viewers
  • Verify image URLs are accessible
  • Ensure proper encoding
  • Check page margins and sizes

File Generation Failures

Check:

  • Template is valid
  • Data is properly formatted
  • File size is within limits
  • Storage permissions are correct
  • API quota not exceeded

Limitations

  • File Size: Max 50MB per document
  • Template Size: Max 5MB template size
  • Generation Time: ~30 seconds for complex documents
  • Images: Max 10MB per image
  • Pages: Recommended max 100 pages per PDF
💡

Tip: Use HTML templates for maximum flexibility - they can be converted to PDF with full styling support!

Example Workflow

Flow:

  1. Customer places order
  2. Retrieve order details
  3. Calculate taxes and totals
  4. Generate invoice from template
  5. Save PDF to cloud storage
  6. Email invoice to customer
  7. Mark order as invoiced
  8. Workflow complete

Related Blocks

  • Set Variable: Prepare document data
  • HTTP Request: Fetch additional data
  • Send Email: Attach generated documents
  • Condition: Generate different templates based on criteria
  • Loop: Generate multiple documents

Need Help?

  • Review Handlebars documentation
  • Test templates with sample data
  • Check generated document in preview
  • Verify variable names and paths
  • Monitor generation logs for errors

Pro Tip: Create a library of reusable templates and use variables to customize them for different workflows!

Indite Documentation v1.4.0
PrivacyTermsSupport