# HTML to PDF Converter: Invoices from Templates, Merge & URLs (`pikoulas/html-to-pdf`) Actor

Turn an HTML template and a list of records into a PDF each, or HTML and web page URLs into PDFs, in a real Chrome: invoices with line items, A4 or Letter, margins, page numbers, headers and footers, and all of them merged into one PDF. A link to each; failures are free.

- **URL**: https://apify.com/pikoulas/html-to-pdf.md
- **Developed by:** [Spyridon Pikoulas](https://apify.com/pikoulas) (community)
- **Categories:** Developer tools, Automation, Integrations
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.00 / 1,000 pdfs

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

## HTML to PDF Converter: Invoices from Templates, Merge & URLs

Give it HTML or the addresses of web pages, and get PDFs back, printed by a real Chrome:

- **A template and its data:** one HTML template with `{{fields}}` and a list of records, one PDF per record:
  invoices with their line items, certificates, tickets, letters. A hundred invoices took 11 seconds.
- **Your own HTML:** finished documents, many in one run through the API.
- **Web pages by URL,** as Chrome prints them, with print or screen styles.
- **A4, Letter, Legal, A3, A5 or Tabloid,** portrait or landscape, your margins, and the document's own CSS
  (`@page`) when it sets a size or margins.
- **Page numbers, headers and footers** on every page, backgrounds and web fonts kept, text selectable.
- **A link to each PDF,** with its page count and size, and all of them **merged into one PDF** if you like.

It costs **$3 per 1,000 PDFs** on Apify's paid plans and $5 on the free plan; each started 20 pages count once. A
document that fails costs nothing.

### What people use it for

- **Invoices and receipts:** a PDF for each order from one HTML template and your orders' data, from Make, Zapier,
  n8n or your own code, and one merged file to print or send to the accountant.
- **Reports:** dashboards, statements and summaries rendered as HTML, sent as PDF.
- **Archiving web pages:** articles, terms, prices and listings as they were on a day.
- **Documents for e-signature and print:** contracts, certificates, tickets and labels.

### How to make PDFs

1. Click **Try for free**; Apify's free plan covers a first run.
2. Paste your **HTML**, add **Page URLs**, or give a **Template** and its **Data**.
3. Pick the **Paper size**, **Margin** and **Page numbers** if you want them.
4. Click **Start**, then open the PDFs from the **Output** tab.

An input with every option:

```json
{
  "html": "<html><head><title>Invoice 1001</title></head><body><h1>Invoice 1001</h1></body></html>",
  "documents": [
    {"html": "<h1>Invoice 1002</h1>", "name": "invoice-1002"},
    "<h1>Invoice 1003</h1>"
  ],
  "urls": ["https://www.wikipedia.org"],
  "paper": "A4",
  "landscape": false,
  "margin": "10mm",
  "pageNumbers": true,
  "headerTemplate": "<div style=\"font-size:9px;width:100%;text-align:right;padding-right:10mm\">ACME Ltd</div>",
  "footerTemplate": "",
  "printBackground": true,
  "media": "print",
  "scale": "1",
  "waitUntil": "load",
  "delaySeconds": 0
}
```

#### From a template

The template is HTML with Mustache fields, filled from each record of `data`: `{{field}}` is escaped,
`{{{field}}}` put in as is, `{{customer.name}}` reads into an object, `{{#items}}...{{/items}}` repeats for each
item of a list (or shows when a value is set), and `{{^items}}...{{/items}}` shows when it's empty. `fileName` is
filled the same way.

```json
{
  "template": "<html><head><title>Invoice {{number}}</title></head><body><h1>Invoice {{number}}</h1><p>Billed to: <b>{{customer.name}}</b><br>{{customer.address}}</p><table>{{#items}}<tr><td>{{name}}</td><td>{{amount}}</td></tr>{{/items}}<tr><td>Total</td><td>{{total}}</td></tr></table>{{#paid}}<p>Paid, thank you.</p>{{/paid}}</body></html>",
  "fileName": "invoice-{{number}}",
  "data": [
    {"number": 1001, "customer": {"name": "Example Corp", "address": "1 Example Street, London"},
     "items": [{"name": "Website design", "amount": "$1,200.00"}, {"name": "Hosting, 12 months", "amount": "$180.00"}],
     "total": "$1,380.00", "paid": true},
    {"number": 1002, "customer": {"name": "Sample & Sons", "address": "2 Sample Road, Leeds"},
     "items": [{"name": "Logo", "amount": "$400.00"}], "total": "$400.00"}
  ],
  "merge": true,
  "pageNumbers": true
}
```

Each record makes `invoice-1001.pdf`, `invoice-1002.pdf` and so on, and with **Merge into one PDF** they're also
put together, in order, in `merged.pdf`.

### Output

```json
{
  "source": "html",
  "url": null,
  "name": null,
  "finalUrl": null,
  "title": "Invoice 1001",
  "status": null,
  "pdfUrl": "https://api.apify.com/v2/key-value-stores/STORE_ID/records/00000-Invoice-1001.pdf",
  "key": "00000-Invoice-1001.pdf",
  "pages": 1,
  "paper": "Letter",
  "landscape": false,
  "sizeBytes": 44173,
  "chargedPdfs": 1,
  "createdAt": "2026-11-10T10:12:49Z",
  "error": null
}
```

`pdfUrl` opens the PDF as long as the run's storage is kept; `key` names it in the run's key-value store, after the
document's `name`, else the page's address or the HTML's `<title>`. A web page's row also has `url`, `finalUrl` after
redirects, and the `status` it answered with. A document that fails comes with `error`, saying why.

With **Merge into one PDF**, `merged.pdf` sits in the same key-value store, linked from the **Output** tab, and the
run's status says how many pages it has. It's free, and it holds only the PDFs made, in the order given: URLs, the
HTML, documents, then the template's records.

### Use it as an API

Apify's API starts a run and returns its dataset as JSON; its Python and JavaScript clients, and
its Make, Zapier and n8n integrations, work the same way.

```bash
curl -X POST "https://api.apify.com/v2/acts/pikoulas~html-to-pdf/run-sync-get-dataset-items?token=YOUR_APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"html": "<h1>Invoice 1001</h1><p>Total: $1,380.00</p>", "paper": "Letter", "pageNumbers": true}'
```

AI agents can call it as a tool through Apify's MCP server: `https://mcp.apify.com?tools=pikoulas/html-to-pdf`.

### How much does it cost?

A PDF is $0.003, up to 20 pages; a longer one counts once per started 20, so a 45-page report is three. A thousand
invoices cost $3, and merging them costs nothing more. Set a spending limit on a run and it stops there, with what it has made so far.

### Good to know

- **Images, fonts and stylesheets** your HTML links to load from their public addresses; inline them (data: URLs) if
  they aren't public. Files on your computer can't load.
- **Headers and footers** are HTML with their styles inline, as Chrome prints them: elements with the classes
  `pageNumber`, `totalPages`, `date`, `title` and `url` get those filled in. They sit in the margin, so keep it at
  10mm or more.
- **Charts and late content:** pick **The network has gone quiet** or an **Extra wait** for scripts that draw after
  the page loads.
- **More memory, more at once:** two documents at a time per GB.
- **A site's refusal is respected** for web pages. It names itself in its User-Agent and reads each site's
  `robots.txt`, one page a second per site at most. A path `robots.txt` refuses isn't printed, and a site that answers
  401, 403 or 451, shows a verification page or answers 429 is left alone for the rest of the run. It uses no proxy and
  doesn't try to get past any of this, so a page behind a check comes back with an `error`.
- Only public addresses are reached, not private networks, for pages and for what your HTML links to.
- **Contact.** The Actor keeps nothing itself: PDFs and results sit in the storage of whoever ran it. Questions or
  requests go to spyridwn.pd@gmail.com.

### FAQ

#### Is it legal to make PDFs of other websites?

Printing a page you can open, for your own records, is what a browser's own Print does; it reads only the pages you
give it, without logging in, and keeps to each site's `robots.txt`. Publishing or selling a copy is another matter:
pages are usually someone's copyrighted work, a site's terms may limit what you do with them, and people named on
them are protected by laws such as the GDPR and the CCPA. If you're unsure, ask a lawyer; Apify's
[Is web scraping legal?](https://blog.apify.com/is-web-scraping-legal/) is a good start.

#### Can I use a template with fields?

Yes: give **Template** and **Data**, as above. For a template language it doesn't take (Handlebars helpers, Jinja
filters), fill it in your own code or automation and send the finished HTML under `documents`, each with a `name`.

#### Something missing or not working?

Open an issue on the **Issues** tab with the input you used, or ask there for a field you need.

If it does what you need, a review on the **Reviews** tab helps others find it.

# Actor input Schema

## `html` (type: `string`):

An HTML document to print: an invoice, a report, a ticket. Images, fonts and styles it links to load from public addresses.

## `urls` (type: `array`):

Web pages to print, as Chrome prints them.

## `documents` (type: `array`):

Many documents in one run, mostly through the API: each an HTML string, or {"html": "...", "name": "invoice-1002"} to name its file.

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

An HTML document with {{fields}} filled from each record of Data, one PDF per record: invoices, certificates, tickets, letters. {{field}} is escaped, {{{field}}} put in as is, {{customer.name}} reads into an object, {{#items}}...{{/items}} repeats for each item of a list (or shows if set), {{^items}}...{{/items}} shows if it's empty.

## `data` (type: `array`):

The records the template is filled with, each an object such as {"number": 1002, "customer": {"name": "Example Corp"}, "items": \[{"name": "Design", "amount": "$1,200.00"}]}. Without data, the template is printed once with its fields empty.

## `fileName` (type: `string`):

Each PDF's name, filled from its record as the template is, such as invoice-{{number}}. Empty names a PDF by its title.

## `merge` (type: `boolean`):

Also puts every PDF made into one, merged.pdf in the run's key-value store, in the order given: URLs, HTML, documents, then the template's records. Free.

## `paper` (type: `string`):

A size set in the document's own CSS (@page { size: ... }) wins.

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

Wider than tall.

## `margin` (type: `string`):

On all four sides, such as 10mm, 0.5in, 1cm, 40px or 0. Margins set in the document's CSS (@page { margin: ... }) win.

## `pageNumbers` (type: `boolean`):

"1 / 3" at the foot of each page.

## `headerTemplate` (type: `string`):

HTML repeated at the top of each page, with its styles inline. Elements with the classes pageNumber, totalPages, date, title and url get those filled in.

## `footerTemplate` (type: `string`):

HTML repeated at the foot of each page, as the header; it replaces the page numbers.

## `printBackground` (type: `boolean`):

Background colours and images printed, as on screen.

## `media` (type: `string`):

Web pages often hide menus and colours in print; screen styles print what you see.

## `scale` (type: `string`):

From 0.1 to 2: below 1 fits more on a page.

## `waitUntil` (type: `string`):

When the document counts as ready to print.

## `delaySeconds` (type: `integer`):

More time before printing, for charts drawn by scripts or late content.

## Actor input object example

```json
{
  "html": "<!doctype html>\n<html><head><meta charset=\"utf-8\"><title>Invoice 1001</title>\n<style>\n  body { font-family: Helvetica, Arial, sans-serif; color: #222; margin: 0; }\n  h1 { color: #0f766e; margin: 0 0 4px; }\n  .muted { color: #666; }\n  table { width: 100%; border-collapse: collapse; margin-top: 24px; }\n  th { background: #0f766e; color: #fff; text-align: left; padding: 8px; }\n  td { border-bottom: 1px solid #ddd; padding: 8px; }\n  .right { text-align: right; }\n  .total td { font-weight: bold; border-bottom: none; }\n</style></head>\n<body>\n  <h1>Invoice 1001</h1>\n  <div class=\"muted\">Issued 10 November 2026 &middot; Due 10 December 2026</div>\n  <p><b>Acme Studio Ltd</b><br>1 Example Street, London</p>\n  <p>Billed to: <b>Example Corp</b></p>\n  <table>\n    <tr><th>Item</th><th class=\"right\">Qty</th><th class=\"right\">Price</th><th class=\"right\">Amount</th></tr>\n    <tr><td>Website design</td><td class=\"right\">1</td><td class=\"right\">$1,200.00</td><td class=\"right\">$1,200.00</td></tr>\n    <tr><td>Hosting, 12 months</td><td class=\"right\">12</td><td class=\"right\">$15.00</td><td class=\"right\">$180.00</td></tr>\n    <tr class=\"total\"><td colspan=\"3\" class=\"right\">Total</td><td class=\"right\">$1,380.00</td></tr>\n  </table>\n</body></html>",
  "documents": [],
  "merge": false,
  "paper": "A4",
  "landscape": false,
  "margin": "10mm",
  "pageNumbers": false,
  "printBackground": true,
  "media": "print",
  "scale": "1",
  "waitUntil": "load",
  "delaySeconds": 0
}
```

# Actor output Schema

## `overview` (type: `string`):

No description

## `files` (type: `string`):

No description

## `merged` (type: `string`):

No description

# 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 = {
    "html": `<!doctype html>
<html><head><meta charset="utf-8"><title>Invoice 1001</title>
<style>
  body { font-family: Helvetica, Arial, sans-serif; color: #222; margin: 0; }
  h1 { color: #0f766e; margin: 0 0 4px; }
  .muted { color: #666; }
  table { width: 100%; border-collapse: collapse; margin-top: 24px; }
  th { background: #0f766e; color: #fff; text-align: left; padding: 8px; }
  td { border-bottom: 1px solid #ddd; padding: 8px; }
  .right { text-align: right; }
  .total td { font-weight: bold; border-bottom: none; }
</style></head>
<body>
  <h1>Invoice 1001</h1>
  <div class="muted">Issued 10 November 2026 &middot; Due 10 December 2026</div>
  <p><b>Acme Studio Ltd</b><br>1 Example Street, London</p>
  <p>Billed to: <b>Example Corp</b></p>
  <table>
    <tr><th>Item</th><th class="right">Qty</th><th class="right">Price</th><th class="right">Amount</th></tr>
    <tr><td>Website design</td><td class="right">1</td><td class="right">$1,200.00</td><td class="right">$1,200.00</td></tr>
    <tr><td>Hosting, 12 months</td><td class="right">12</td><td class="right">$15.00</td><td class="right">$180.00</td></tr>
    <tr class="total"><td colspan="3" class="right">Total</td><td class="right">$1,380.00</td></tr>
  </table>
</body></html>`,
    "documents": []
};

// Run the Actor and wait for it to finish
const run = await client.actor("pikoulas/html-to-pdf").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 = {
    "html": """<!doctype html>
<html><head><meta charset=\"utf-8\"><title>Invoice 1001</title>
<style>
  body { font-family: Helvetica, Arial, sans-serif; color: #222; margin: 0; }
  h1 { color: #0f766e; margin: 0 0 4px; }
  .muted { color: #666; }
  table { width: 100%; border-collapse: collapse; margin-top: 24px; }
  th { background: #0f766e; color: #fff; text-align: left; padding: 8px; }
  td { border-bottom: 1px solid #ddd; padding: 8px; }
  .right { text-align: right; }
  .total td { font-weight: bold; border-bottom: none; }
</style></head>
<body>
  <h1>Invoice 1001</h1>
  <div class=\"muted\">Issued 10 November 2026 &middot; Due 10 December 2026</div>
  <p><b>Acme Studio Ltd</b><br>1 Example Street, London</p>
  <p>Billed to: <b>Example Corp</b></p>
  <table>
    <tr><th>Item</th><th class=\"right\">Qty</th><th class=\"right\">Price</th><th class=\"right\">Amount</th></tr>
    <tr><td>Website design</td><td class=\"right\">1</td><td class=\"right\">$1,200.00</td><td class=\"right\">$1,200.00</td></tr>
    <tr><td>Hosting, 12 months</td><td class=\"right\">12</td><td class=\"right\">$15.00</td><td class=\"right\">$180.00</td></tr>
    <tr class=\"total\"><td colspan=\"3\" class=\"right\">Total</td><td class=\"right\">$1,380.00</td></tr>
  </table>
</body></html>""",
    "documents": [],
}

# Run the Actor and wait for it to finish
run = client.actor("pikoulas/html-to-pdf").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 '{
  "html": "<!doctype html>\\n<html><head><meta charset=\\"utf-8\\"><title>Invoice 1001</title>\\n<style>\\n  body { font-family: Helvetica, Arial, sans-serif; color: #222; margin: 0; }\\n  h1 { color: #0f766e; margin: 0 0 4px; }\\n  .muted { color: #666; }\\n  table { width: 100%; border-collapse: collapse; margin-top: 24px; }\\n  th { background: #0f766e; color: #fff; text-align: left; padding: 8px; }\\n  td { border-bottom: 1px solid #ddd; padding: 8px; }\\n  .right { text-align: right; }\\n  .total td { font-weight: bold; border-bottom: none; }\\n</style></head>\\n<body>\\n  <h1>Invoice 1001</h1>\\n  <div class=\\"muted\\">Issued 10 November 2026 &middot; Due 10 December 2026</div>\\n  <p><b>Acme Studio Ltd</b><br>1 Example Street, London</p>\\n  <p>Billed to: <b>Example Corp</b></p>\\n  <table>\\n    <tr><th>Item</th><th class=\\"right\\">Qty</th><th class=\\"right\\">Price</th><th class=\\"right\\">Amount</th></tr>\\n    <tr><td>Website design</td><td class=\\"right\\">1</td><td class=\\"right\\">$1,200.00</td><td class=\\"right\\">$1,200.00</td></tr>\\n    <tr><td>Hosting, 12 months</td><td class=\\"right\\">12</td><td class=\\"right\\">$15.00</td><td class=\\"right\\">$180.00</td></tr>\\n    <tr class=\\"total\\"><td colspan=\\"3\\" class=\\"right\\">Total</td><td class=\\"right\\">$1,380.00</td></tr>\\n  </table>\\n</body></html>",
  "documents": []
}' |
apify call pikoulas/html-to-pdf --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,pikoulas/html-to-pdf"
        }
    }
}
```

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/0eT2NsqDOV3bmnM95/builds/BCMlvhqtuVLVr56U5/openapi.json
