# HTML to PDF — Render Raw HTML or Templates to PDF Files (`ponderable_hydrometer/html-to-pdf`) Actor

Render your own HTML to PDF with a real Chrome engine: invoices, reports, tickets. Pass HTML strings (with CSS), choose paper size, margins and orientation, optional header and footer. Each result links to the PDF.

- **URL**: https://apify.com/ponderable_hydrometer/html-to-pdf.md
- **Developed by:** [Ponderable Hydrometer](https://apify.com/ponderable_hydrometer) (community)
- **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 results

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 — Render Raw HTML or Templates to PDF Files

**Your HTML in, a print-ready PDF out.** Invoices, reports, certificates and tickets render with a real Chrome engine, so CSS, web fonts and tables look the way they do in the browser. Send many documents in one run from an API call or a workflow tool.

### Input

| Field | Type | Default | Description |
|-------|------|---------|-------------|
| `documents` | array | — | Objects `{"name", "html"}` or HTML strings. |
| `paperFormat` | string | `A4` | A4, Letter, Legal, A3, A5. |
| `landscape` | boolean | `false` | Rotate the page. |
| `marginMm` | integer | `15` | Margin on all sides. |
| `footerText` | string | — | Footer with page numbers. |

### What you get

One row per document: `name`, `fileUrl` (the PDF in the run's key-value store), `bytes`, `pages`, `paperFormat`, `landscape`.

### Output sample

```json
{
  "name": "invoice-1001",
  "fileUrl": "https://api.apify.com/v2/key-value-stores/abc/records/invoice-1001.pdf",
  "bytes": 31245,
  "pages": 1,
  "paperFormat": "A4",
  "landscape": false
}
```

### Good to know

- Images and fonts referenced by absolute URLs are loaded; relative paths have no base and are skipped.
- To capture an existing web page instead of your own HTML, use a URL-to-PDF tool.
- Files follow the retention of the run's key-value store.

### Pricing

Pay per result — **$3.00 per 1,000 results** (one PDF = one result), plus Apify's standard per-run start event ($0.00005 per GB of memory, so a fraction of a cent per run). No subscription.

# Actor input Schema

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

A list of {"html": "...", "name": "invoice-42"} objects, or plain HTML strings.

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

Page size.

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

Rotate the page.

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

Margin on all sides.

## `footerText` (type: `string`):

Optional footer on every page. Page numbers are added automatically when set.

## Actor input object example

```json
{
  "documents": [
    {
      "name": "invoice-1001",
      "html": "<html><body style=\"font-family:sans-serif\"><h1>Invoice #1001</h1><p>Billed to: ACME Ltd</p><table border=\"1\" cellpadding=\"6\"><tr><th>Item</th><th>Amount</th></tr><tr><td>Consulting</td><td>$1,200</td></tr></table></body></html>"
    },
    {
      "name": "hello",
      "html": "<h1>Hello PDF</h1><p>Rendered by Chrome.</p>"
    },
    {
      "name": "report",
      "html": "<h2>Weekly report</h2><ul><li>Revenue up 4%</li><li>Churn flat</li></ul>"
    }
  ],
  "paperFormat": "A4",
  "landscape": false,
  "marginMm": 15,
  "footerText": ""
}
```

# Actor output Schema

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

All rows produced by this run, as JSON.

# 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 = {
    "documents": [
        {
            "name": "invoice-1001",
            "html": "<html><body style=\"font-family:sans-serif\"><h1>Invoice #1001</h1><p>Billed to: ACME Ltd</p><table border=\"1\" cellpadding=\"6\"><tr><th>Item</th><th>Amount</th></tr><tr><td>Consulting</td><td>$1,200</td></tr></table></body></html>"
        },
        {
            "name": "hello",
            "html": "<h1>Hello PDF</h1><p>Rendered by Chrome.</p>"
        },
        {
            "name": "report",
            "html": "<h2>Weekly report</h2><ul><li>Revenue up 4%</li><li>Churn flat</li></ul>"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("ponderable_hydrometer/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 = { "documents": [
        {
            "name": "invoice-1001",
            "html": "<html><body style=\"font-family:sans-serif\"><h1>Invoice #1001</h1><p>Billed to: ACME Ltd</p><table border=\"1\" cellpadding=\"6\"><tr><th>Item</th><th>Amount</th></tr><tr><td>Consulting</td><td>$1,200</td></tr></table></body></html>",
        },
        {
            "name": "hello",
            "html": "<h1>Hello PDF</h1><p>Rendered by Chrome.</p>",
        },
        {
            "name": "report",
            "html": "<h2>Weekly report</h2><ul><li>Revenue up 4%</li><li>Churn flat</li></ul>",
        },
    ] }

# Run the Actor and wait for it to finish
run = client.actor("ponderable_hydrometer/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 '{
  "documents": [
    {
      "name": "invoice-1001",
      "html": "<html><body style=\\"font-family:sans-serif\\"><h1>Invoice #1001</h1><p>Billed to: ACME Ltd</p><table border=\\"1\\" cellpadding=\\"6\\"><tr><th>Item</th><th>Amount</th></tr><tr><td>Consulting</td><td>$1,200</td></tr></table></body></html>"
    },
    {
      "name": "hello",
      "html": "<h1>Hello PDF</h1><p>Rendered by Chrome.</p>"
    },
    {
      "name": "report",
      "html": "<h2>Weekly report</h2><ul><li>Revenue up 4%</li><li>Churn flat</li></ul>"
    }
  ]
}' |
apify call ponderable_hydrometer/html-to-pdf --silent --output-dataset

```

## MCP server setup

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