# HTML to PDF: Web Pages, HTML & Invoice Templates in Bulk (`blueberry_rainstorm/html-to-pdf`) Actor

Turn web pages, HTML documents or an HTML template plus JSON rows (invoices, certificates, reports) into PDFs. Page size, margins, landscape, headers, footers and page numbers. Cookie banners hidden. You only pay for PDFs that succeed.

- **URL**: https://apify.com/blueberry_rainstorm/html-to-pdf.md
- **Developed by:** [Pandapi](https://apify.com/blueberry_rainstorm) (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

$3.00 / 1,000 pdf createds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

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: Web Pages, HTML & Invoice Templates in Bulk

Convert **web pages, HTML documents or an HTML template filled with JSON data** into clean PDF files, with a real Chrome browser.

- 🌐 **URL to PDF**: any public page, one PDF per URL, with cookie banners hidden and lazy images loaded
- 📝 **HTML to PDF**: paste a full HTML document (inline CSS, web fonts, images) and get one PDF
- 🧾 **Template + data to many PDFs**: one Handlebars template and a JSON array of rows gives one PDF per row. Perfect for **invoices, receipts, certificates, tickets, letters and reports**
- 📐 **Page layout**: A4, Letter, Legal, A3, A5 or Tabloid, portrait or landscape, margins, scale, background colors
- 🔢 **Headers, footers and page numbers** ("3 / 12") on every page
- 🏷️ **Your file names**: `invoice-{{number}}.pdf` instead of random keys
- 💸 **You only pay for PDFs that are created.** Broken URLs and failed documents are free. No start fee.

### Use cases

- **Invoices and receipts** from your shop, CRM or n8n / Make / Zapier workflow data
- **Certificates** for course or event attendees, from a spreadsheet exported as JSON
- **Reports** built as HTML (charts, tables) and sent as PDF attachments
- **Archiving web pages** for compliance, legal evidence or research
- **Saving articles and documentation** as printable PDFs

### How to use it

1. Pick what to convert: **Web page URLs**, an **HTML document**, or an **HTML template** with **Data rows**. You can mix all three in one run.
2. Choose the page size, margins and footer.
3. Run it. Each PDF is stored in the run's key-value store and listed in the dataset with a download link.

#### Example: invoices from JSON

```json
{
  "template": "<html><body style=\"font-family:Arial\"><h1>Invoice {{number}}</h1><p>Bill to: {{customer}}</p><table>{{#each items}}<tr><td>{{name}}</td><td>{{qty}} × {{formatNumber price}}</td><td>{{formatNumber (multiply qty price)}}</td></tr>{{/each}}</table><h3>Total: {{formatNumber (sumProduct items \"qty\" \"price\")}} USD</h3></body></html>",
  "data": [
    { "number": "INV-001", "customer": "Acme Ltd", "items": [{ "name": "Design", "qty": 2, "price": 150 }, { "name": "Hosting", "qty": 12, "price": 9.5 }] },
    { "number": "INV-002", "customer": "Globex", "items": [{ "name": "Audit", "qty": 1, "price": 900 }] }
  ],
  "fileNameTemplate": "invoice-{{number}}",
  "pageFormat": "A4",
  "pageNumbers": true
}
```

This gives `invoice-INV-001.pdf` and `invoice-INV-002.pdf`.

**Template language**: [Handlebars](https://handlebarsjs.com/guide/). `{{field}}` is HTML-escaped, `{{{field}}}` inserts raw HTML, `{{#each list}}…{{/each}}` loops, `{{#if field}}…{{/if}}` tests. Extra helpers: `multiply`, `add`, `sum list "field"`, `sumProduct list "qty" "price"`, `formatNumber value 2`, `uppercase`, `date`, `eq`. `{{_index}}` is the row number (1, 2, 3…).

#### Example: web pages with page numbers

```json
{ "urls": [{ "url": "https://en.wikipedia.org/wiki/PDF" }, { "url": "https://example.com" }], "pageFormat": "Letter", "pageNumbers": true }
```

### Input

| Field | Default | Notes |
|---|---|---|
| Web page URLs | | Public http(s) pages, one PDF each |
| HTML document / File name | | One PDF from your HTML |
| HTML template / Data rows / File name template | | One PDF per data row |
| Page size | A4 | A4, Letter, Legal, A3, A5, Tabloid |
| Landscape | Off | |
| Margins | 10 mm | CSS style: `10mm`, `10mm 15mm`, `1in 0.5in 1in 0.5in`. 18 mm top/bottom when a header or footer is on |
| Print backgrounds | On | |
| Scale | 1 | 0.1 to 2 |
| Page numbers | Off | Adds "3 / 12" at the bottom |
| Header HTML / Footer HTML | | Use `<span class="pageNumber">`, `totalPages`, `date`, `title`, `url`. Give it a `font-size` |
| CSS media | Print | Print = like the browser's Save as PDF. Screen = like the page looks on screen |
| Hide cookie banners | On | For URLs |
| Hide these elements | | CSS selectors, e.g. `.chat-widget` |
| Wait until / Wait for selector / Extra delay | Page loaded | For slow or script-heavy pages |
| Timeout per document | 45 s | |
| Parallel documents | 4 | |
| Max documents | 10,000 | |

### Output

Every PDF is saved in the run's **key-value store** under its file name. The **dataset** has one row per document:

```json
{
  "source": "template",
  "url": null,
  "rowIndex": 0,
  "fileName": "invoice-INV-001.pdf",
  "status": "ok",
  "pdfUrl": "https://api.apify.com/v2/key-value-stores/abc123/records/invoice-INV-001.pdf",
  "pages": 1,
  "bytes": 18121,
  "title": null,
  "httpStatus": null,
  "finalUrl": null,
  "error": null,
  "durationSecs": 0.1,
  "createdAt": "2026-11-13T12:46:10.512Z"
}
```

Failed documents have `status: "failed"` and an `error`, for example `The page answered HTTP 404.`

### Pricing

**$3 per 1,000 PDFs** ($0.003 each), whatever the page count. No start fee. Failed documents are free. Apify's free plan credit covers about 1,600 PDFs a month.

| You make | You pay |
|---|---|
| 100 invoices | $0.30 |
| 1,000 web page PDFs | $3.00 |
| 10,000 certificates | $30.00 |

### Use it from the API, n8n, Make or Zapier

Call the actor with the [Apify API](https://docs.apify.com/api/v2) or the Apify app in n8n, Make or Zapier, then read the dataset for the `pdfUrl` links.

```bash
curl -X POST "https://api.apify.com/v2/acts/blueberry_rainstorm~html-to-pdf/run-sync-get-dataset-items?token=YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"html": "<h1>Hello PDF</h1>", "fileName": "hello"}'
```

### FAQ

**Can I use my own fonts?** Yes. Load them in your HTML with `@font-face` or a Google Fonts `<link>`. The actor waits for fonts before printing.

**Why does my page look different from the screen?** Many sites have print styles. Set **CSS media** to **Screen** to get what you see in the browser.

**My header or footer is tiny or missing.** Chrome prints header and footer HTML at a very small default size: set `font-size` (e.g. 9px) in your template, and keep top/bottom margins at 12 mm or more.

**Can it open pages behind a login?** No. It converts public pages and the HTML you send.

**Can my HTML read local files?** No. `file:` URLs are blocked inside documents.

**How long are the PDFs kept?** In the run's key-value store, for as long as your Apify plan keeps run storage. Download them or copy them to your own storage if you need them longer.

### Acceptable use

Convert only pages and content you have the right to copy. Don't use this tool to copy paywalled or copyrighted material for redistribution. You are responsible for the documents you create.

### More from Pandapi 🐼

Pandapi makes friendly, no-nonsense data tools: simple input, clean output, and fair pay-per-result prices. Found a bug or need a feature? Open an issue on the Issues tab and we answer fast.

- [Web Page to Markdown](https://apify.com/blueberry_rainstorm/web-page-to-markdown): clean, chunked Markdown from any URL or sitemap, ready for AI and RAG
- [PDF to Text, Markdown & Excel](https://apify.com/blueberry_rainstorm/pdf-to-text-markdown): text, Markdown and real Excel tables from any PDF, with OCR
- [Website Contact Details Scraper](https://apify.com/blueberry_rainstorm/website-contact-finder): business emails, phones and social links, one row per website
- [Website Screenshot](https://apify.com/blueberry_rainstorm/website-screenshot): full-page and mobile screenshots or PDFs of many URLs at once
- [Broken Link Checker](https://apify.com/blueberry_rainstorm/broken-link-checker): every 404, dead link and redirect on a site, with the page it is on
- [Public Tenders Feed](https://apify.com/blueberry_rainstorm/public-tenders-feed): government tenders and contract awards from six official portals
- [App Store Reviews Scraper](https://apify.com/blueberry_rainstorm/app-store-reviews-scraper): iOS reviews, ratings and app details from about 180 countries
- [Google Play Reviews Scraper](https://apify.com/blueberry_rainstorm/google-play-reviews-scraper): Android reviews with developer replies, ratings and app data, many languages
- [Hacker News Scraper](https://apify.com/blueberry_rainstorm/hacker-news-scraper): stories, comments, Show HN and job posts, filtered your way

# Actor input Schema

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

Public pages to save as PDF, one PDF per URL. You can also (or instead) give an HTML document or an HTML template below.

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

A full HTML document (with inline CSS, images by URL or data URI) to turn into one PDF.

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

Name of the PDF made from the HTML document, e.g. report-2026-11. Default: document.pdf.

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

Handlebars template, e.g. <h1>Invoice {{number}}</h1>{{#each items}}<p>{{name}}: {{formatNumber (multiply qty price)}}</p>{{/each}}. Helpers: multiply, add, sum, sumProduct, formatNumber, uppercase, date, eq. Use {{{field}}} for raw HTML.

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

JSON array of objects. Each object fills the template once and gives one PDF, e.g. \[{"number": "INV-001", "items": \[{"name": "Design", "qty": 2, "price": 150}]}].

## `fileNameTemplate` (type: `string`):

Name of each PDF made from the template, e.g. invoice-{{number}}. {{\_index}} is the row number. Default: document-{{\_index}}.

## `pageFormat` (type: `string`):

Paper size of every page.

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

Turn pages sideways (wide tables, dashboards).

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

CSS style: "10mm", "10mm 15mm" (top/bottom, left/right) or four values. Units mm, cm, in or px. Empty = 10 mm, or 18 mm top/bottom when there is a header or footer.

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

Keep background colors and images, like Chrome's "Background graphics" option.

## `scale` (type: `number`):

1 = 100%. Lower it to fit wide pages.

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

Adds a small "3 / 12" footer. Ignored when you give your own Footer HTML.

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

Printed at the top of every page. Use classes pageNumber, totalPages, date, title, url, e.g. <div style="font-size:9px;margin-left:10mm"><span class="title"></span></div>. Set a font-size: the default is tiny.

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

Printed at the bottom of every page (same classes as the header). Overrides the page numbers option.

## `cssMediaType` (type: `string`):

Print uses the page's print styles. Screen keeps the on-screen look.

## `hideCookieBanners` (type: `boolean`):

Hides common cookie and consent popups (OneTrust, Cookiebot, Didomi and more) before printing web pages.

## `hideSelectors` (type: `string`):

CSS selectors to hide before printing, e.g. .chat-widget, header nav

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

When the page counts as ready to print.

## `waitForSelector` (type: `string`):

Wait until this CSS selector appears before printing.

## `delaySecs` (type: `integer`):

Extra wait before printing, for animations or charts.

## `timeoutSecs` (type: `integer`):

A document that takes longer fails (and is free).

## `maxConcurrency` (type: `integer`):

How many documents are printed at the same time.

## `maxDocuments` (type: `integer`):

Stop after this many PDFs.

## Actor input object example

```json
{
  "urls": [
    {
      "url": "https://en.wikipedia.org/wiki/PDF"
    }
  ],
  "pageFormat": "A4",
  "landscape": false,
  "printBackground": true,
  "scale": 1,
  "pageNumbers": false,
  "cssMediaType": "print",
  "hideCookieBanners": true,
  "waitUntil": "load",
  "delaySecs": 0,
  "timeoutSecs": 45,
  "maxConcurrency": 4,
  "maxDocuments": 10000
}
```

# Actor output Schema

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

No description

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

No description

## `files` (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 = {
    "urls": [
        {
            "url": "https://en.wikipedia.org/wiki/PDF"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("blueberry_rainstorm/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 = { "urls": [{ "url": "https://en.wikipedia.org/wiki/PDF" }] }

# Run the Actor and wait for it to finish
run = client.actor("blueberry_rainstorm/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 '{
  "urls": [
    {
      "url": "https://en.wikipedia.org/wiki/PDF"
    }
  ]
}' |
apify call blueberry_rainstorm/html-to-pdf --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,blueberry_rainstorm/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/Ra9dHkyifLkgcqTmG/builds/AFmgeCojf2v6Oqqob/openapi.json
