# HTML to PDF Converter - Convert a URL or HTML string to PDF (`cuantic_data/html-to-pdf-converter`) Actor

Renders a URL or a raw HTML string you provide into a PDF file using a real headless Chrome, and returns a download link. No login, no third-party API, no data beyond what you send.

- **URL**: https://apify.com/cuantic\_data/html-to-pdf-converter.md
- **Developed by:** [Cuantic Data](https://apify.com/cuantic_data) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 pdf generateds

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 Converter — Convert a URL or HTML string to PDF

Converts a public URL or raw HTML into a PDF using a real headless Chrome
(not an approximate renderer). No third-party API keys, no login.

### What it does

- Accepts **a URL** (navigates to it and exports the page as rendered) or
  **raw HTML** (renders it directly) — one or the other, not both.
- Returns the PDF as a downloadable file (`pdfUrl`) plus metadata (size,
  page format, orientation).
- Supports page size (`A4`/`Letter`/`Legal`), landscape orientation, and
  whether to print CSS backgrounds/colors.

### Who it's for

- Generating reports, invoices or receipts as PDF from HTML built by
  another system (e.g. a backend that builds the HTML and needs the final
  PDF).
- Saving a PDF copy of a public page (e.g. terms and conditions, an
  article) with the real layout, not plain text.

### Input

| Field | Type | Required | Description |
|---|---|---|---|
| `url` | string | One of the two | Public http(s) URL to convert. **Takes precedence over `html` if both are present.** |
| `html` | string | One of the two | Raw HTML to convert (max 5 MB). Pre-filled with a sample document (so the actor's daily automated test always has input to run); ignored automatically if `url` is also filled in. |
| `format` | string | No (default `A4`) | `A4`, `Letter` or `Legal`. |
| `landscape` | boolean | No (default `false`) | Landscape orientation. |
| `printBackground` | boolean | No (default `true`) | Print CSS backgrounds and colors. |

**Precedence:** you need `url` OR `html`. If you send only one, that one is
used. If you send both (for example because you filled in `url` but left the
`html` field's sample prefill in place), `url` wins and `html` is silently
ignored — except a `WARN` is logged and the output/`RUN-SUMMARY` include
`ignoredHtml: true` so it's traceable. The run only fails if **neither**
field is provided.

```json
{ "url": "https://example.com" }
```

or

```json
{ "html": "<h1>Report</h1><p>Content</p>", "landscape": true }
```

### Output

```json
{
  "source": "url",
  "url": "https://example.com",
  "ignoredHtml": false,
  "format": "A4",
  "landscape": false,
  "printBackground": true,
  "sizeBytes": 35496,
  "pdfUrl": "https://api.apify.com/v2/key-value-stores/<storeId>/records/OUTPUT.pdf",
  "generatedAt": "2026-09-20T03:39:59.236Z"
}
```

`ignoredHtml` is `true` only when both `url` and `html` were sent and `html`
was discarded in favor of `url` (see Precedence above).

The PDF file is stored in the run's Key-Value Store; `pdfUrl` is the direct
download link (public, as long as storage hasn't expired per the account's
plan).

### Pricing

Pay-per-event, provisional. Starting reference: USD 0.01 per document
generated (`03-plan.md` §2).

### How to call it

```bash
curl "https://api.apify.com/v2/acts/cuantic-data~html-to-pdf-converter/run-sync-get-dataset-items?token=YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com"}'
```

### Terms and limits

See [`TERMS.md`](./TERMS.md): uses real Chrome via Puppeteer (Apache
License 2.0), rendering only the content the user supplies.

### FAQ

**Can I send both `url` and `html`, in case one fails?**
You can, but it won't try both: if both are provided, `url` is used and
`html` is ignored (with a warning in the log and `ignoredHtml: true` in the
output). It's not a way to get a fallback — just send the one you want
converted.

**Found a bug?**
Email `cuanticwindows@gmail.com` — we reply within 72 hours.

***

See `build/README.md` for how to run tests and publish this Actor.

# Actor input Schema

## `url` (type: `string`):

Public http(s) URL. The actor navigates to it with real Chrome and converts the rendered page to PDF. If you fill this in, it takes precedence over "html" below (which keeps a sample prefill for the daily automated test) — the sample is ignored, not treated as an error.

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

Full HTML (or a fragment) to render directly, without needing it published at any URL. Comes pre-filled with a sample document so the actor's daily automated test always has something to run — if you fill in "url" above, that sample is ignored automatically (with a warning in the log), you don't need to clear this field.

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

Paper size of the generated PDF, e.g. A4 or Letter.

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

Render the page in landscape orientation instead of portrait.

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

Include CSS background colors and images in the PDF. Off by default to keep files small and printer-friendly.

## Actor input object example

```json
{
  "html": "<h1>Sample document</h1><p>Generated by HTML to PDF Converter.</p>",
  "format": "A4",
  "landscape": false,
  "printBackground": true
}
```

# Actor output Schema

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

Source, format and size of the generated PDF, plus the download link.

## `pdfFile` (type: `string`):

The generated PDF, ready to download.

## `runSummary` (type: `string`):

Source, size in bytes and PDF download link.

# 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 = {
    "html": "<h1>Sample document</h1><p>Generated by HTML to PDF Converter.</p>"
};

// Run the Actor and wait for it to finish
const run = await client.actor("cuantic_data/html-to-pdf-converter").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 = { "html": "<h1>Sample document</h1><p>Generated by HTML to PDF Converter.</p>" }

# Run the Actor and wait for it to finish
run = client.actor("cuantic_data/html-to-pdf-converter").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 '{
  "html": "<h1>Sample document</h1><p>Generated by HTML to PDF Converter.</p>"
}' |
apify call cuantic_data/html-to-pdf-converter --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,cuantic_data/html-to-pdf-converter"
        }
    }
}
```

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/h2h5E3968gYjaslIj/builds/1gWeE4jyagPVAfHMi/openapi.json
