# Screenshot & HTML to PDF API (`ensorcelling_melilot/screenshot-pdf`) Actor

Screenshot or PDF any list of web pages, or turn your own HTML into a PDF. Full page, phone or desktop size, dark mode, cookie banners hidden, element capture. Direct file links. $0.004 per capture, charged only when it works.

- **URL**: https://apify.com/ensorcelling_melilot/screenshot-pdf.md
- **Developed by:** [ensorcelling \_melilot](https://apify.com/ensorcelling_melilot) (community)
- **Categories:** Developer tools, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$4.00 / 1,000 capture createds

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

## Screenshot & HTML to PDF API

Give it a list of web pages (or your own HTML) and get back **screenshots (PNG, JPEG) or PDFs** as direct file links. Built on a real Chrome browser, so JavaScript-heavy pages render properly.

### What you can do

- **Screenshot a list of URLs**: full page or just the first screen, at any size from phone to 4K.
- **Make PDFs of web pages**: A4, Letter, Legal or A3, portrait or landscape, with backgrounds.
- **Turn your own HTML into a PDF**: invoices, reports, certificates, tickets. Paste the HTML in the input or send it through the API.
- **Mobile and dark-mode captures**: narrow viewport, touch and mobile user agent, `prefers-color-scheme: dark`.
- **Clean captures**: common cookie banners and chat widgets are hidden by default.
- **Capture one element**: pass a CSS selector such as `#chart` to crop to it.
- **Wait for slow pages**: wait for the network to go quiet, for an element to appear, or for a fixed extra delay.

### Output

One row per page in the dataset:

| Field | Example |
|---|---|
| `url` | `https://example.com/` |
| `status` | `ok`, `failed` or `skipped` |
| `fileUrl` | direct link to the PNG, JPEG or PDF |
| `fileSize` | bytes |
| `title` | the page title |
| `httpStatus` | `200` |
| `error` | the reason, when a capture failed |

The files themselves sit in the run's key-value store as `capture-0001.png`, `capture-0002.png`...

### Pricing

**$0.004 per capture** ($4 per 1,000). You are only charged for captures that succeed. Failed pages, skipped inputs and blocked addresses are free. No start fee.

### Good to know

- Pages behind a login or paywall are captured as a visitor would see them. You can send extra request headers (for example a language) but there is no cookie or login support yet.
- Very long pages are cut at 16,000 pixels high.
- For safety the Actor refuses private and local addresses (localhost, 10.x, 192.168.x, cloud metadata addresses), including links a page tries to load from them.
- Some sites detect and block automated browsers. Those show up as failed rows with the reason.
- You are responsible for having the right to capture the pages you submit and for how you use the images.

### Use it from code

```bash
curl -X POST "https://api.apify.com/v2/acts/<username>~screenshot-pdf/run-sync-get-dataset-items?token=<TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{"urls":["https://example.com"],"format":"pdf"}'
```

HTML to PDF: send `{"html":"<h1>Invoice 42</h1>","format":"pdf"}` and read `fileUrl` from the result.

# Actor input Schema

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

Pages to capture, one per line. Each page gives one file.

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

Optional. A full HTML document (or fragment) to render instead of, or as well as, the URLs. Handy for invoices, reports and certificates. It is rendered like a web page and cannot reach private networks.

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

What to produce for every page: a PNG image, a smaller JPEG image, or a PDF document.

## `fullPage` (type: `boolean`):

Capture the whole scrollable page, not just the first screen. Ignored for PDFs (PDFs always cover all pages). Very long pages are cut at 16,000 pixels high.

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

Browser window width in pixels. 1280 is a laptop, 390 is a phone.

## `viewportHeight` (type: `integer`):

Browser window height in pixels. For non-full-page screenshots this is the image height.

## `deviceScaleFactor` (type: `integer`):

1 is normal, 2 gives sharp images for retina screens (twice the pixels in each direction, bigger files).

## `mobile` (type: `boolean`):

Pretend to be a phone: touch events and a mobile user agent. Combine with a narrow viewport width such as 390.

## `darkMode` (type: `boolean`):

Ask pages for their dark colour scheme (prefers-color-scheme: dark), for sites that support it.

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

When the page counts as loaded. 'load' is the default. 'networkidle' waits for the network to go quiet and suits slow single-page apps.

## `delaySeconds` (type: `integer`):

Extra time to wait after loading before the capture, for animations and lazy content.

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

Optional CSS selector, for example #chart. The capture waits (up to 15 seconds) until this element appears.

## `hideCookieBanners` (type: `boolean`):

Hide common cookie consent bars and chat widgets before capturing. It covers the usual consent tools, not every site.

## `clipSelector` (type: `string`):

Optional CSS selector. For screenshots, only this element is captured instead of the whole page.

## `pdfFormat` (type: `string`):

Paper size for PDFs.

## `pdfLandscape` (type: `boolean`):

Print PDFs sideways.

## `pdfPrintBackground` (type: `boolean`):

Include background colours and images in PDFs.

## `extraHeaders` (type: `object`):

Optional headers sent with every page request, as JSON, for example {"Accept-Language": "de"}. Values are not stored or logged.

## `maxConcurrency` (type: `integer`):

How many pages to render in parallel. Raise for long lists if you give the Actor more memory.

## Actor input object example

```json
{
  "urls": [
    "https://example.com"
  ],
  "format": "png",
  "fullPage": true,
  "viewportWidth": 1280,
  "viewportHeight": 800,
  "deviceScaleFactor": 1,
  "mobile": false,
  "darkMode": false,
  "waitUntil": "load",
  "delaySeconds": 1,
  "hideCookieBanners": true,
  "pdfFormat": "A4",
  "pdfLandscape": false,
  "pdfPrintBackground": true,
  "maxConcurrency": 3
}
```

# Actor output Schema

## `captures` (type: `string`):

One row per page: status, the link to the screenshot or PDF file, size, page title and any error.

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

The screenshot and PDF files in the run's key-value store.

## `summary` (type: `string`):

How many captures worked, failed or were skipped.

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

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

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

```

## MCP server setup

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