# Template Document Generator — Handlebars to PDF/HTML (`hipersoft/template-document-generator`) Actor

Merge your data into a Handlebars template and get back a document — PDF, HTML or plain text. Generate invoices, reports, receipts, certificates and contracts in bulk from an n8n, Make or Zapier workflow.

- **URL**: https://apify.com/hipersoft/template-document-generator.md
- **Developed by:** [hiper soft](https://apify.com/hipersoft) (community)
- **Categories:** Developer tools, Other
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.0025 / document generated

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Template Document Generator — Handlebars to PDF, HTML or Text

**Merge your data into a Handlebars template and get a finished document back** — a PDF, an HTML file or plain text. Perfect for invoices, reports, receipts, certificates and contracts, one at a time or in bulk.

### What it does

- Fills a **Handlebars/HTML template** with your data and produces a document.
- Outputs **PDF, HTML or plain text** — you choose the format.
- Handles **one document** (pass `data`) or a **whole batch** (pass `rows` — one document per row, a mail-merge).
- Saves every document to storage and returns a direct link to each file.

### Use cases

- **Invoices & receipts** — turn each order into a branded PDF invoice.
- **Reports** — merge metrics into a styled report on a schedule.
- **Certificates & contracts** — generate personalized certificates or agreements for a list of people.
- **Bulk mail-merge** — feed an array of rows and get one document per row in a single run.
- **The document step in your workflow** — drop it into **n8n, Make or Zapier**: pass your row data, get a PDF back to email, upload or archive downstream.

### Input

```json
{
  "template": "<h1>Invoice {{number}}</h1><p>Billed to: {{customer}}</p><p>Total: {{total}}</p>",
  "rows": [
    { "number": "INV-001", "customer": "Acme", "total": "$42.00" },
    { "number": "INV-002", "customer": "Globex", "total": "$99.00" }
  ],
  "output": "pdf"
}
```

| Field | Type | Description |
|---|---|---|
| `template` | string | The Handlebars/HTML template with `{{placeholders}}`. |
| `templateUrl` | string | Fetch the template from a URL (used when `template` is empty). |
| `data` | object | Field values for a single document. |
| `rows` | array | Array of objects — one document per row (batch / mail-merge). |
| `output` | string | `pdf`, `html` or `txt` (default `pdf`). |
| `pdfFormat` | string | Paper size for PDF: A4, Letter, Legal… |
| `landscape` | boolean | Landscape orientation for PDF. |
| `filePrefix` | string | Prefix for generated file names. |

### Output

```json
{ "index": 0, "format": "pdf", "bytes": 48213, "resultUrl": "https://api.apify.com/v2/key-value-stores/.../records/doc-0001.pdf", "ok": true }
```

#### Output schema

| Field | Type | Description |
|---|---|---|
| `index` | integer | Position of the row in your input. |
| `format` | string | Format of the produced document. |
| `bytes` | integer | Size of the generated file. |
| `resultUrl` | string (URL) | Direct link to the document. |
| `ok` | boolean | Whether the document was generated. |

### FAQ

**Can I generate one PDF per row?** Yes — pass an array in `rows` and you get one document per row in a single run.

**Which template syntax is supported?** Handlebars — `{{field}}` placeholders, `{{#each}}`, `{{#if}}` and common helpers.

**Can I use it in n8n?** Yes — run it from the Apify node in your workflow, or via [integrations](https://apify.com/integrations) and the [Apify API](https://docs.apify.com/api/v2).

### Notes

Original clean-room implementation.

# Actor input Schema

## `template` (type: `string`):

The document template, written in Handlebars/HTML. Use {{placeholders}} for your data fields, e.g. <h1>Invoice {{number}}</h1><p>Total: {{total}}</p>. Leave empty if you provide a Template URL instead.

## `templateUrl` (type: `string`):

A URL to fetch the template from (used when Template is empty). Point it at a hosted Handlebars/HTML template file.

## `data` (type: `object`):

An object of field values to merge into the template. Produces one document. Example: { "number": "INV-001", "customer": "Acme", "total": "$42.00" }.

## `rows` (type: `array`):

An array of objects — one document is produced per row (a mail-merge, e.g. a batch of invoices). When provided, this is used instead of Data.

## `output` (type: `string`):

The file format for each generated document.

## `pdfFormat` (type: `string`):

Paper size for PDF output.

## `landscape` (type: `boolean`):

Use landscape orientation for PDF output.

## `filePrefix` (type: `string`):

Prefix for the generated file names, e.g. "invoice" → invoice-0001.pdf.

## Actor input object example

```json
{
  "template": "<h1>Invoice {{number}}</h1>\n<p>Billed to: {{customer}}</p>\n<p>Total: {{total}}</p>",
  "output": "pdf",
  "pdfFormat": "A4",
  "landscape": false,
  "filePrefix": "doc"
}
```

# Actor output Schema

## `results` (type: `string`):

The results as dataset items.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "template": `<h1>Invoice {{number}}</h1>
<p>Billed to: {{customer}}</p>
<p>Total: {{total}}</p>`
};

// Run the Actor and wait for it to finish
const run = await client.actor("hipersoft/template-document-generator").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "template": """<h1>Invoice {{number}}</h1>
<p>Billed to: {{customer}}</p>
<p>Total: {{total}}</p>""" }

# Run the Actor and wait for it to finish
run = client.actor("hipersoft/template-document-generator").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "template": "<h1>Invoice {{number}}</h1>\\n<p>Billed to: {{customer}}</p>\\n<p>Total: {{total}}</p>"
}' |
apify call hipersoft/template-document-generator --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,hipersoft/template-document-generator"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/6xxPXLaJYl3NlAXkx/builds/IPZbHYbCDgjdpehF1/openapi.json
