# HTML to PDF, URL to PDF & Markdown to PDF (Bulk, Templates) (`toowl/html-to-pdf`) Actor

Turn web pages, HTML or Markdown into PDFs in bulk with headless Chrome: A4/Letter, margins, landscape, backgrounds, page numbers. Fill one HTML template from your data to make hundreds of invoices, certificates or tickets. Pay per PDF.

- **URL**: https://apify.com/toowl/html-to-pdf.md
- **Developed by:** [Chalid Ade](https://apify.com/toowl) (community)
- **Features:** Limited permissions
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.00 / 1,000 pdfs generated

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/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, URL to PDF & Markdown to PDF — bulk, with templates

A PDF API that just works: give it **web page URLs**, **HTML**, **Markdown**, or **one HTML template plus a list of records**, and get pixel-perfect PDFs from real headless Chrome. One PDF per document, download links in the dataset, and everything in one ZIP.

Typical jobs:

- 🧾 **Invoices, receipts, certificates, tickets, payslips** from your data (mail-merge style), hundreds per run
- 🌐 **Save web pages as PDF** for archiving, compliance, offline reading or evidence
- 📝 **Markdown to PDF** for docs, READMEs, LLM output and reports
- 🔌 A drop-in **HTML-to-PDF endpoint** for Make, Zapier, n8n or your backend, with no Chrome to host yourself

### What you get

- Real Chrome rendering: modern CSS (flexbox, grid, web fonts), JavaScript, charts, SVG
- **A4, Letter, Legal, A3, A5, Tabloid**, portrait or landscape, margins in mm, scale
- **Page numbers** ("1 / 5") in the footer, **backgrounds** on or off, or the page's own `@page` size
- **Wait options**: network idle, load, DOM ready, plus an extra delay for animations
- **Hide elements** with CSS selectors (cookie banners, chat widgets) before printing
- **Selectable text and clickable links** in the PDF, plus a document outline from headings
- Markdown with GitHub tables, task lists and code blocks, in a clean paper style
- **Template mail-merge**: `{{field}}` (escaped), `{{{field}}}` (raw HTML), `{{customer.name}}` (nested)

### Input examples

**Invoices from data**

```json
{
  "template": "<h1>Invoice {{fileName}}</h1><p>Bill to: {{customer.name}}</p><p>Total: {{total}}</p>",
  "records": [
    { "fileName": "INV-1042", "customer": { "name": "Acme Ltd" }, "total": "$1,250.00" },
    { "fileName": "INV-1043", "customer": { "name": "Globex" }, "total": "$980.00" }
  ],
  "format": "A4",
  "pageNumbers": true
}
```

**Web pages**

```json
{
  "urls": [{ "url": "https://example.com/pricing" }, { "url": "https://example.com/terms" }],
  "hideSelectors": ["#cookie-banner"],
  "media": "screen"
}
```

**Mixed bulk documents**

```json
{
  "documents": [
    { "name": "readme", "markdown": "# Hello\n\nSome **Markdown**." },
    { "name": "letter", "html": "<html><body><h1>Dear customer</h1></body></html>" },
    { "url": "https://example.com/report" }
  ]
}
```

### Output

One dataset row per document:

```json
{
  "name": "INV-1042",
  "pages": 1,
  "sizeKb": 15.7,
  "pdfUrl": "https://api.apify.com/v2/key-value-stores/…/records/0001-INV-1042.pdf",
  "source": "html"
}
```

Plus `pdfs.zip` (when there is more than one PDF) and a `SUMMARY` record in the run's key-value store.

### Pricing

Pay per event: one `pdf-generated` per PDF, whatever its page count. Documents that fail (a page that does not load, a timeout) are free. Cap spending with "Max cost per run".

### Tips

- Images and fonts in HTML must be reachable by URL (or embedded as `data:` URLs).
- For HTML you control, `@page { size: A4; margin: 0 }` plus "Use the page's own @page size" gives you full control.
- Sites behind a login or a bot wall won't render; this Actor prints what an anonymous browser sees.

### Free browser version

Need one Markdown file as PDF or Word? [toowl.my.id/en/markdown-to-pdf](https://toowl.my.id/en/markdown-to-pdf/) does it in your browser for free.

### Call it from your code

```bash
curl -X POST "https://api.apify.com/v2/acts/toowl~html-to-pdf/run-sync-get-dataset-items" \
  -H "Authorization: Bearer $APIFY_TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"urls":[{"url":"https://example.com"}],"format":"A4","pageNumbers":true}'
```

The same call works from Python (`apify-client`), JavaScript, Make, Zapier and n8n (Apify app/node or a plain HTTP request).

### Use it from AI agents (MCP)

Add this Actor as a tool to Claude, Cursor, VS Code or any MCP client through Apify's MCP server:

```
https://mcp.apify.com/?actors=toowl/html-to-pdf
```

The agent can then pass file URLs and read the results itself.

### More toowl file APIs

Speech to text & subtitles, AI vocal remover, text to speech, AI object remover, PDF to Markdown, PDF to Word & Excel, HTML/URL to PDF, OCR, Office to PDF, PDF compressor, PDF merge/split, PDF password protect, PDF to image, image to PDF, bulk watermark, image converter and compressor, background remover, AI upscaler, image to SVG, QR code and barcode generators, QR/barcode reader, favicon generator, video compressor, frame extractor and audio converter. All pay per file, all batch-friendly: [toowl.my.id/en/api](https://toowl.my.id/en/api/).

Questions or a format that fails? Open an issue on the Actor's **Issues** tab.

# Actor input Schema

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

Pages to save as PDF, exactly as Chrome prints them (one PDF per URL).

## `markdown` (type: `string`):

One Markdown document (GitHub flavour: tables, task lists, code). Becomes a clean paper-style PDF.

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

One full HTML document, CSS included. Remote images and fonts are loaded.

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

Many documents at once: \[{ "html": "…", "name": "invoice-1042" }, { "markdown": "# Hi" }, { "url": "https://…" }]. The name becomes the file name.

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

Mail-merge: one PDF per object in Records. {{field}} is replaced by that record's value (HTML-escaped), {{{field}}} inserts raw HTML, {{customer.name}} reaches nested values.

## `records` (type: `array`):

Data for the template, one object per PDF. A fileName (or name / id) field names the file.

## `format` (type: `string`):

Paper size of every page.

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

Turn pages sideways (good for wide tables and dashboards).

## `marginMm` (type: `integer`):

Blank border around every page.

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

Adds "1 / 5" at the bottom of every page.

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

Keep background colours and images (off = what a browser prints by default).

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

Zoom of the content, 0.1–2 (e.g. 0.8 fits wide pages).

## `font` (type: `string`):

Typeface for Markdown documents.

## `preferCssPageSize` (type: `boolean`):

If the HTML sets @page { size: … }, use that instead of Paper size.

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

print uses the site's print stylesheet; screen makes the PDF look like the page on screen.

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

When the page counts as loaded. Network idle waits for late images and scripts.

## `waitMs` (type: `integer`):

Wait this long after loading, for animations or charts.

## `hideSelectors` (type: `array`):

Cookie banners, chat bubbles, ads… e.g. #cookie-banner, .intercom-launcher

## `viewportWidth` (type: `integer`):

Window width the page is laid out in before printing (affects responsive sites).

## `locale` (type: `string`):

Accept-Language sent to web pages (e.g. id-ID), for sites that switch language.

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

A document that takes longer fails (and is not charged).

## `zip` (type: `boolean`):

With more than one PDF, also saves pdfs.zip.

## Actor input object example

```json
{
  "urls": [
    {
      "url": "https://en.wikipedia.org/wiki/Portable_Document_Format"
    }
  ],
  "format": "A4",
  "landscape": false,
  "marginMm": 12,
  "pageNumbers": false,
  "printBackground": true,
  "scale": "1",
  "font": "sans",
  "preferCssPageSize": false,
  "media": "print",
  "waitUntil": "networkidle",
  "waitMs": 0,
  "viewportWidth": 1280,
  "locale": "en-US",
  "timeoutSecs": 60,
  "zip": true
}
```

# Actor output Schema

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

One row per document, with a download link for its PDF.

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

PDFs (and pdfs.zip with all of them) in the default key-value store, plus a SUMMARY record.

# 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/Portable_Document_Format"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("toowl/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/Portable_Document_Format" }] }

# Run the Actor and wait for it to finish
run = client.actor("toowl/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/Portable_Document_Format"
    }
  ]
}' |
apify call toowl/html-to-pdf --silent --output-dataset

```

## MCP server setup

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