# 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:** [Hipersoft](https://apify.com/hipersoft) (community)
- **Categories:** Developer tools, Other
- **Features:** Limited permissions
- **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?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## 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.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# 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.

![Template Document Generator input — configure the options in the Apify Console](https://api.apify.com/v2/key-value-stores/SUfvnaFLd9z9eBCtV/records/template-document-generator-input.png)

### 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

![Template Document Generator output — the results as a clean dataset](https://api.apify.com/v2/key-value-stores/SUfvnaFLd9z9eBCtV/records/template-document-generator-output.png)

```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. |

### Related Actors

Explore more data tools from the same author:

- [HTML to PDF — Render URL or HTML to PDF](https://apify.com/hipersoft/html-to-pdf)
- [Images to PDF — Combine Photos into One PDF](https://apify.com/hipersoft/images-to-pdf)
- [Markdown to HTML Converter — Bulk](https://apify.com/hipersoft/markdown-to-html)
- [PDF Form Filler — Fill AcroForm Fields](https://apify.com/hipersoft/pdf-fill-form)

Plug the results straight into your stack with [Make](https://apify.com/integrations/make), [Zapier](https://apify.com/integrations/zapier) or any of Apify's [integrations](https://apify.com/integrations).

### 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/it3NfRI7haQUKJv99/openapi.json
