# HTML to PDF & URL to PDF Converter - Bulk, Headless Chrome (`northbell/html-to-pdf`) Actor

Turn web page links or raw HTML into PDF files in bulk with headless Chrome: A4/Letter, margins, landscape, backgrounds, header and footer with page numbers. Results are files with public links.

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

## Pricing

from $2.40 / 1,000 documents

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 & URL to PDF Converter - Bulk, Headless Chrome

**Turn web page links or raw HTML into PDF files in bulk.** Give it URLs (or a dataset from another Actor, or a piece of HTML) and get one PDF per input as a file with a public link, one dataset row per input. It prints with headless Chrome, so the PDF looks like Chrome's own "Save as PDF": A4, Letter, Legal or A3, margins, landscape, background colours, a header and footer with page numbers, and a wait for a selector for pages that load with JavaScript. One bad page never fails the run: it becomes a row with a plain error message, and the rest carry on.

**Try it now - the input is already filled in.** Press **Start**. It converts `example.com` and RFC 1149 (rfc-editor.org) to A4 PDFs with a "page / total pages" footer. In our own local run with this input (Windows, Chromium 159, 2 pages at a time): **2 PDFs, 3 PDF pages, 67,595 and 30,812 bytes, about 8 seconds** for the whole run including browser start. That is **$0.006** (plus $0.00005 for the run start).

### What you pay

| Event | Price | When |
| --- | --- | --- |
| `pdf` | $0.003 | per PDF stored |
| `apify-actor-start` | $0.00005 | once per run |

- You are charged for a PDF only after it is saved. Errors, rejected links, bot-check pages and pages skipped by "Only changed" are free.
- Set "Maximum total charge" on the run as your cap. The Actor checks the charge limit before it stores each PDF and stops cleanly when the next one does not fit.

### Built so that runs finish

- **A timeout on every page.** 60 seconds by default (`timeoutSeconds`, 5 to 300). A page that does not load becomes an error row, and the browser tab is closed.
- **Errors are rows.** `status: "error"` and a sentence that says why: "The server answered 404.", "The page did not finish loading within 60 seconds.", "The element given in Wait for selector did not appear...". The run still ends as succeeded.
- **Downloads are blocked.** A link that is a file (a ZIP, or a PDF that Chrome would download) is an error row, not a download.
- **Bounded parallelism.** 2 pages at a time by default, up to 5 (`concurrency`). The default fits the 2048 MB the Actor starts with.
- **Honest browser.** It identifies as Chrome with " html-to-pdf (Apify Actor)" added to the user agent. No proxies, no stealth or anti-bot plugins. If a page answers with a bot check (Cloudflare "Just a moment", Turnstile or hCaptcha only), the row says "the page asked for a bot check; this tool does not get around it", free.

### Run it after your scraper

If another Actor collects page links (a news scraper, a blog or documentation crawler, a search results scraper), this Actor can archive every page as a PDF after each of its runs:

1. In Apify Console, open that Actor and go to **Integrations**.
2. Add **Run Actor** (on "Run succeeded") and pick this Actor.
3. Use an input like this, with the name of the field that holds the page link:

```json
{
  "datasetId": "{{resource.defaultDatasetId}}",
  "urlField": "url",
  "format": "A4",
  "onlyChanged": true,
  "maxItems": 200
}
```

A dotted path such as `page.url` reaches into nested fields; the field may hold one link or a list of links. If the dataset has no links, nothing runs and nothing is charged. Each output row keeps a small `sourceItem` (the field name, the link and the row's `id` if it has one) so you can match PDFs to the original rows.

### Run it on a schedule with only changed pages

Turn on `onlyChanged` and schedule the run. The Actor keeps a hash of each page's visible text in a key-value store named `html-to-pdf-seen` in your account. On the next run:

- the text is the same: `status: "skipped"`, `changed: false`, no PDF, **free**;
- the text is different: a new PDF with the date in its file name (`...-2026-11-22.pdf`), `changed: true`;
- the page was not seen before: a PDF, `changed: null` (nothing to compare with).

Only the text you can read is compared (extra spaces and line breaks do not count). A page with a clock, a visitor counter or rotating ads counts as changed every time; hide those with `extraCss` (for example `.ad, #clock { display: none !important; }`) or the hash will move on every run. The list is saved at the end of the run. If the store cannot be opened, the run stops before charging anything. Pages are still opened to compare, so a skipped page costs run time, not money. "Only changed" applies to links, not to raw HTML.

### Options

| Input | Default | What it does |
| --- | --- | --- |
| `urls` | example.com, an RFC page | web pages to convert (http, https) |
| `html` | none | raw HTML text, one PDF (up to 5 MB) |
| `datasetId`, `urlField` | - , `url` | read links from another Actor's dataset; dotted paths and lists allowed |
| `format` | `A4` | `A4`, `Letter`, `Legal`, `A3` |
| `landscape` | off | sideways pages |
| `margins` | 15/12/18/12 mm | `top`, `right`, `bottom`, `left` in mm, cm, in or px; one text like `"12mm"` sets all four |
| `printBackground` | on | include background colours and images |
| `mediaType` | `print` | `print` (the page's print style) or `screen` (the page as on screen) |
| `waitForSelector` | none | wait until this CSS selector is on the page |
| `waitMs` | 0 | extra wait after load, 0 to 30000 |
| `headerTemplate`, `footerTemplate` | footer with page numbers | HTML for the top and bottom of every page |
| `extraCss` | none | CSS added before printing, e.g. to hide cookie banners |
| `onlyChanged` | off | skip pages whose text has not changed since the last run |
| `allowScripts` | URLs: on, raw HTML: off | set it to override for every input |
| `lazyLoadScroll` | on | scroll once so images that load on scroll are in the PDF |
| `maxItems` | 200 | inputs per run (links, HTML and dataset together) |
| `maxPages` | 200 | PDF pages per file; a longer page is cut off |
| `concurrency` | 2 | pages at the same time, 1 to 5 |
| `timeoutSeconds` | 60 | per page, 5 to 300 |

Notes:

- **Header and footer.** Chrome fills in the classes `date`, `title`, `url`, `pageNumber` and `totalPages`. Give the template a `font-size` in its style (Chrome's default is tiny) and keep the top or bottom margin large enough for it. With only a footer, there is no header (and the other way round).
- **Hiding cookie banners.** Use `extraCss` with the banner's selector: `#onetrust-banner-sdk, .cookie-banner { display: none !important; }`. It does not click "accept" for you.
- **Raw HTML.** It is rendered with scripts off unless you set `allowScripts`. Images and styles that the HTML links to are fetched like any page request (public addresses only); `data:` images inside raw HTML work.
- **Cut-off pages.** If a row's `pages` equals `maxPages`, the page was probably longer and the PDF was cut.

### Output

One dataset row per input. The PDF is stored in the run's key-value store, and `pdfUrl` is its public link.

```json
{
  "url": "https://example.com",
  "status": "ok",
  "error": null,
  "pdfUrl": "https://api.apify.com/v2/key-value-stores/8ef17a6a-9f37-455a-bbd7-5ae313bdaeed/records/example-com-327c3fda.pdf",
  "pdfKey": "example-com-327c3fda.pdf",
  "pages": 1,
  "bytes": 67595,
  "title": "Example Domain",
  "changed": null,
  "textHash": "43338e32beb5871d10be1ac1816172af"
}
```

This row is from our local run of the prefilled input; the store id in the link is the one that run used on our machine. On Apify it is your run's store. For a failed input `status` is `error`, `error` says why and `pdfUrl` is `null`. For a skipped one `status` is `skipped` and `changed` is `false`. `textHash` is the hash of the page's visible text (the same text gives the same hash). For raw HTML, `url` is `null`. The files stay as long as your Apify storage retention keeps the run.

### Limits

- Pages must be reachable without a login. Sites that show a bot check are not worked around; those pages come back as errors. Some sites block datacenter traffic and answer 403; the row shows the server's answer.
- Links to private, local-network and link-local addresses are rejected, and so is every request a page makes to such an address (images, frames, scripts, redirects). `file:` and `chrome:` addresses are refused. `data:` is only allowed inside raw HTML, so inline `data:` images on a page opened from a link are not loaded. Limit: the host name is checked here and Chrome looks it up again itself, so an address that changes between the two is not caught.
- At most 200 PDF pages per file, 5 MB of raw HTML, 20,000 characters per header or footer template.
- A very long or very heavy page can hit the timeout; raise `timeoutSeconds`, or lower `concurrency`.
- Fonts that the page does not provide are the ones installed on the Apify machine; the look can differ a little from your own browser.
- You are responsible for having the right to copy the pages you give it.

### 日本語

Web ページの URL(または他の Actor のデータセット、HTML テキスト)を、ヘッドレス Chrome で PDF に一括変換します。A4/Letter/Legal/A3、余白、横向き、背景の印刷、ページ番号入りのヘッダー・フッター、セレクタの出現待ち、cookie バナーを隠す CSS に対応。結果は実行のキー・バリューストアに PDF として保存され、公開リンクが入力1件につき1行のデータセットで返ります。スクレイパーの実行後に「取得した全ページを PDF で保存」する使い方と、スケジュール実行で「本文が変わったページだけ新しい日付入り PDF を作る」使い方(`onlyChanged`)ができます。料金は PDF 1件 $0.003。保存できた分だけ課金され、失敗・スキップは無料です。Bot チェック(Cloudflare・hCaptcha 等)が出るページはエラー行になり、回避はしません。プライベート/ローカルのアドレスへのアクセスは拒否されます。変換するページの権利はご自身でご確認ください。

# Actor input Schema

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

Web pages to turn into PDF (http or https). Or leave empty and give HTML or a Dataset ID. Pages that need a login, and private or local network addresses, come back as errors, free.

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

Optional. HTML text to turn into one PDF (up to 5 MB). Scripts do not run in it unless you tick Allow scripts. Links in it (images, styles) are fetched like any page request.

## `datasetId` (type: `string`):

Read page links from this Apify dataset (e.g. the dataset of a scraper run). Use {{resource.defaultDatasetId}} when you connect this Actor as an integration after another Actor.

## `urlField` (type: `string`):

Name of the field that holds the page link. A dotted path works (page.url). The field may hold one link or a list of links; every link is converted.

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

Page size of the PDF.

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

Turn the pages sideways.

## `margins` (type: `object`):

Page margins as lengths in mm, cm, in or px: top, right, bottom, left. Leave room at the bottom for a footer. A single text such as "12mm" in the JSON also works and sets all four sides.

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

Without it, Chrome leaves out background colours and background images, as when printing.

## `mediaType` (type: `string`):

Which CSS rules apply. Print is what Chrome's Save as PDF uses; screen keeps the on-screen look of pages without a print style.

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

Optional CSS selector. The PDF is made after this element is on the page (for pages that load their content with JavaScript). If it does not show up within the page timeout, the row is an error.

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

Wait this long after the page has loaded (and after the selector), 0 to 30000.

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

Optional HTML for the top of every page. Chrome fills in the classes date, title, url, pageNumber and totalPages, for example <span class="pageNumber"></span>. Set a font-size in the style (Chrome's default is tiny) and keep the top margin large enough.

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

Optional HTML for the bottom of every page, same classes as the header. The prefilled footer prints "page / total pages". Empty: no footer (and no header unless you give one).

## `extraCss` (type: `string`):

Optional CSS added to every page before the PDF is made. Use it to hide cookie banners and pop-ups, for example #cookie-banner, .cc-window { display: none !important; }.

## `onlyChanged` (type: `boolean`):

For scheduled runs. Keeps a hash of each page's visible text in a key-value store named html-to-pdf-seen in your account. A page whose text is the same as last time is skipped (free); a page that is new or changed gets a new dated PDF, and changed is true when it differs from last time. Applies to links, not to raw HTML.

## `allowScripts` (type: `boolean`):

Leave it as it is: JavaScript runs on pages from a link (most pages need it) and does not run in raw HTML. Tick or untick to set it for every input.

## `lazyLoadScroll` (type: `boolean`):

Scrolls each page down once (up to about 3 seconds) so images that load while scrolling are in the PDF. Needs scripts.

## `maxItems` (type: `integer`):

Cap on inputs per run, counting links, HTML and dataset together (unchanged pages count too, because the page is opened to compare). Inputs over the cap are left for the next run.

## `maxPages` (type: `integer`):

A longer page is cut off after this many PDF pages (up to 200).

## `concurrency` (type: `integer`):

How many pages are open in parallel (1 to 5). Each one uses memory; the default 2 fits 2048 MB.

## `timeoutSeconds` (type: `integer`):

A page that has not loaded in this time becomes an error row (free) and the run goes on. 5 to 300.

## Actor input object example

```json
{
  "urls": [
    "https://example.com",
    "https://www.rfc-editor.org/rfc/rfc1149.html"
  ],
  "urlField": "url",
  "format": "A4",
  "landscape": false,
  "margins": {
    "top": "15mm",
    "right": "12mm",
    "bottom": "18mm",
    "left": "12mm"
  },
  "printBackground": true,
  "mediaType": "print",
  "waitMs": 0,
  "footerTemplate": "<div style=\"font-size:9px;width:100%;text-align:center;color:#666\"><span class=\"pageNumber\"></span> / <span class=\"totalPages\"></span></div>",
  "onlyChanged": false,
  "lazyLoadScroll": true,
  "maxItems": 200,
  "maxPages": 200,
  "concurrency": 2,
  "timeoutSeconds": 60
}
```

# Actor output Schema

## `pdfs` (type: `string`):

Status, PDF link, page count and size per input.

# 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": [
        "https://example.com",
        "https://www.rfc-editor.org/rfc/rfc1149.html"
    ],
    "format": "A4",
    "margins": {
        "top": "15mm",
        "right": "12mm",
        "bottom": "18mm",
        "left": "12mm"
    },
    "footerTemplate": "<div style=\"font-size:9px;width:100%;text-align:center;color:#666\"><span class=\"pageNumber\"></span> / <span class=\"totalPages\"></span></div>"
};

// Run the Actor and wait for it to finish
const run = await client.actor("northbell/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": [
        "https://example.com",
        "https://www.rfc-editor.org/rfc/rfc1149.html",
    ],
    "format": "A4",
    "margins": {
        "top": "15mm",
        "right": "12mm",
        "bottom": "18mm",
        "left": "12mm",
    },
    "footerTemplate": "<div style=\"font-size:9px;width:100%;text-align:center;color:#666\"><span class=\"pageNumber\"></span> / <span class=\"totalPages\"></span></div>",
}

# Run the Actor and wait for it to finish
run = client.actor("northbell/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": [
    "https://example.com",
    "https://www.rfc-editor.org/rfc/rfc1149.html"
  ],
  "format": "A4",
  "margins": {
    "top": "15mm",
    "right": "12mm",
    "bottom": "18mm",
    "left": "12mm"
  },
  "footerTemplate": "<div style=\\"font-size:9px;width:100%;text-align:center;color:#666\\"><span class=\\"pageNumber\\"></span> / <span class=\\"totalPages\\"></span></div>"
}' |
apify call northbell/html-to-pdf --silent --output-dataset

```

## MCP server setup

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