# HTML to PDF Converter: URL to PDF & Website to PDF (`ferrolark/html-to-pdf`) Actor

HTML to PDF and URL to PDF converter: turn a website, webpage or raw HTML into a PDF with headless Chrome. For invoices, receipts, reports and page archives. A4 or Letter, margins, page numbers, wait for selector, print or screen CSS. Private IPs blocked. $0.005 per PDF.

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

$5.00 / 1,000 pdf rendereds

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 & URL to PDF API (Headless Chrome)

Print web pages or your own HTML to PDF with headless Chromium, the same engine as Chrome's "Save as PDF".

- **URLs or raw HTML** (also base64 HTML files from n8n or Make), up to 20 documents per run.
- **Page setup:** A4, Letter, Legal, A3, A5 or Tabloid, landscape, margins, scale, page ranges and "page / total" numbers in the footer.
- **Loading control:** wait for network idle, a CSS selector or an extra delay; print or screen CSS; JavaScript on or off.
- **Safe:** every browser request goes through a guard that blocks private and local addresses, and the counts are in each row.
- **Manifest:** pages, bytes, page title, final URL and HTTP status.

Typical uses: invoices and receipts from HTML templates, archiving pages for compliance, reports from dashboards, and PDFs generated by AI agents from HTML.

### Real example

Two web pages and a small HTML invoice with page numbers:

```json
{
  "urls": [
    "https://example.com/",
    "https://en.wikipedia.org/wiki/PDF"
  ],
  "html": "<h1>Invoice 42</h1><p>Total: 10 EUR</p>",
  "pageNumbers": true
}
```

- Run time: 18.8 s on Apify at 1,024 MB (most of it is starting Chromium).
- Platform usage: $0.0014.
- Your cost: 3 PDFs × $0.005 = **$0.015**.

| Output | Source | Pages | Bytes | Render time |
|---|---|---|---|---|
| `example-com.pdf` | example.com | 1 | 49,609 | 0.6 s |
| `en-wikipedia-org-wiki-PDF.pdf` | Wikipedia | 24 | 480,416 | 0.9 s |
| `document.pdf` | HTML | 1 | 14,170 | 0.5 s |

### Price and limits

- **$0.005 per PDF rendered.**
- Pages that fail (HTTP 4xx/5xx, timeouts, private addresses) are listed in `OUTPUT.errors` and not charged.
- Limits: 20 documents per run, 5 MB of HTML each, 50 MB per PDF, 120 s timeout per page.

### Input

| Field | Default | What it does |
|---|---|---|
| `urls` | none | Public pages to print. |
| `html` | none | Raw HTML. Use absolute URLs for images and CSS. |
| `files` | none | `[{"base64": "...", "name": "invoice.html"}]`. |
| `paperFormat`, `landscape`, `marginMm`, `scale` | `A4`, `false`, 10, 1 | Page setup. |
| `pageNumbers` | `false` | Footer with page / total. |
| `pageRanges` | all | For example `1-3`. |
| `waitUntil` | `networkidle` | `networkidle`, `load` or `domcontentloaded`. |
| `waitForSelector`, `delayMs` | none, 0 | Wait for dynamic content. |
| `media` | `print` | `print` or `screen` CSS. |
| `javascript` | `true` | Turn off for static HTML. |
| `viewportWidth` | 1280 | For responsive layouts. |
| `createShareableUrl` | `false` | Also return signed links that work without an Apify token. |

### Call it from code, n8n or an AI agent

**API (synchronous):**

```bash
curl -X POST "https://api.apify.com/v2/acts/ferrolark~html-to-pdf/run-sync-get-dataset-items?maxTotalChargeUsd=0.1" \
  -H "Authorization: Bearer $APIFY_TOKEN" -H "Content-Type: application/json" \
  -d '{"urls": ["https://example.com/"], "paperFormat": "Letter"}'
```

**n8n:** paste this workflow on the canvas (Ctrl+V). Add a Header Auth credential with the name `Authorization` and the value `Bearer <your Apify token>`, and use it in both HTTP nodes. The second node downloads the PDF as an n8n binary.

```json
{
  "name": "Ferrolark html-to-pdf",
  "nodes": [
    {
      "parameters": {},
      "name": "When clicking Test workflow",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.apify.com/v2/acts/ferrolark~html-to-pdf/run-sync-get-dataset-items?maxTotalChargeUsd=0.05",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "{\"html\": \"<h1>Invoice 42</h1><p>Total: 10 EUR</p>\", \"pageNumbers\": true}",
        "options": {
          "timeout": 300000
        }
      },
      "name": "Run Actor",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "url": "={{ $json.downloadUrl }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "name": "Download file",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        0
      ]
    }
  ],
  "connections": {
    "When clicking Test workflow": {
      "main": [
        [
          {
            "node": "Run Actor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Actor": {
      "main": [
        [
          {
            "node": "Download file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
```

**AI agents (MCP):** add the Apify MCP server (`https://mcp.apify.com`) to Claude, Cursor or any MCP client and allow `ferrolark/html-to-pdf`. The agent gets a typed tool with the input above.

### FAQ

**Can it log in or pass cookie banners?**

No. It prints public pages as an anonymous visitor. For your own pages, render the HTML yourself and send it in `html`.

**Why are fonts different from my browser?**

The container has common open fonts (DejaVu, Liberation, Noto). Use web fonts in your HTML for exact branding.

**Is it the same as Apify's free HTML to PDF?**

It adds base64 input, page numbers, a request guard, per-document errors that are not charged and a manifest for automations.

### More Ferrolark tools

- [Brand Name Availability Checker](https://apify.com/ferrolark/brand-name-checker): domains, GitHub, npm, PyPI and more in one report.
- [Domain Intelligence Report](https://apify.com/ferrolark/domain-intelligence-report): WHOIS, DNS, email security, SSL and hosting for any domain.
- [Launch Asset Pack](https://apify.com/ferrolark/launch-asset-pack): favicons, PWA icons, OG image and head tags from one logo.
- [Live Deploy QA](https://apify.com/ferrolark/live-deploy-qa): meta tags, canonical, robots, OG image and favicon of your deployed routes, with diffs between deploys.
- [Sitemap Delta](https://apify.com/ferrolark/sitemap-delta): new, removed and broken URLs in any sitemap since the last run.
- [RSS Delta](https://apify.com/ferrolark/rss-delta): only new RSS, Atom and JSON Feed items, de-duplicated.
- [PDF Merge API](https://apify.com/ferrolark/pdf-merge-api): merge PDFs from URLs or base64 with page ranges and a SHA-256 manifest.
- [PDF Split API](https://apify.com/ferrolark/pdf-split-api): split a PDF by page ranges or every N pages, or extract pages, with a ZIP and manifest.
- [Image Convert](https://apify.com/ferrolark/image-convert): PNG, JPG, WebP, AVIF and HEIC conversion (SVG input too) from URLs or base64.
- [Image Compress & Resize](https://apify.com/ferrolark/image-compress-resize): resize images and compress them to a target size in KB, WebP or AVIF.
- [PDF to Image](https://apify.com/ferrolark/pdf-to-image): PDF pages to PNG, JPG or WebP at the DPI you choose.
- [Image to PDF](https://apify.com/ferrolark/image-to-pdf): JPG, PNG, HEIC and WebP images to one PDF, JPEGs embedded without recompression.
- [PDF Compress](https://apify.com/ferrolark/pdf-compress): smaller PDFs, lossless or with image downsampling; charged only when smaller.
- [Markdown to PDF](https://apify.com/ferrolark/markdown-to-pdf): Markdown with tables, code and footnotes to a clean PDF.
- [DOCX to PDF](https://apify.com/ferrolark/docx-to-pdf): Word, Excel, PowerPoint and ODT to PDF with LibreOffice.
- [Data Convert](https://apify.com/ferrolark/data-convert): CSV, JSON, NDJSON and Excel XLSX in any direction.

***

*Built by Ferrolark.*

# Actor input Schema

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

Public web pages to print. Up to 20 documents per run (URLs + HTML).

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

Raw HTML to print (up to 5 MB). Relative links do not resolve; use absolute URLs or inline data: images.

## `files` (type: `array`):

For n8n/Make binaries: a list of {"base64": "...", "name": "invoice.html"} objects.

## `outputFileName` (type: `string`):

URL outputs are named after the URL.

## `paperFormat` (type: `string`):

Page size of the PDF.

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

Landscape orientation.

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

Same margin on all sides.

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

Adds 'page / total' at the bottom.

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

Keep background colors and images.

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

0.1 to 2. Lower values fit more content per page.

## `pageRanges` (type: `string`):

Optional, for example 1-3, 5. Empty = all pages.

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

Let the document's own @page rule decide the size.

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

networkidle waits for the page to go quiet (best for JS sites); if it never does, the page is printed as loaded.

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

Optional, for example #invoice or .chart-ready.

## `delayMs` (type: `integer`):

Wait this long after loading, for animations.

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

print uses the site's print stylesheet; screen looks like the browser.

## `javascript` (type: `boolean`):

Turn off for static HTML to make rendering faster and safer.

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

Affects responsive layouts.

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

Page load timeout.

## `createShareableUrl` (type: `boolean`):

Also return signed links that work without an Apify token. Anyone with a link can download that file.

## Actor input object example

```json
{
  "urls": [
    "https://example.com/"
  ],
  "files": [],
  "outputFileName": "document.pdf",
  "paperFormat": "A4",
  "landscape": false,
  "marginMm": 10,
  "pageNumbers": false,
  "printBackground": true,
  "scale": "1",
  "preferCssPageSize": false,
  "waitUntil": "networkidle",
  "delayMs": 0,
  "media": "print",
  "javascript": true,
  "viewportWidth": 1280,
  "timeoutSecs": 60,
  "createShareableUrl": false
}
```

# Actor output Schema

## `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": [
        "https://example.com/"
    ],
    "files": []
};

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

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

```

## MCP server setup

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