# HTML to PDF & URL to PDF API - Website Screenshots (`autofacts/universal-web-printer`) Actor

A powerful web rendering Actor that converts URLs and HTML to PDF, PNG, JPEG, or WebP. Features smart scroll-stitch for full-page captures, element-level extraction, reading mode, watermark and PDF merging.

- **URL**: https://apify.com/autofacts/universal-web-printer.md
- **Developed by:** [Proooxy](https://apify.com/autofacts) (community)
- **Categories:** Developer tools, Automation, MCP servers
- **Features:** Limited permissions
- **Stats:** 64 total users, 9 monthly users, 100.0% runs succeeded, 3 bookmarks
- **User rating**: No ratings yet

## Pricing

from $4.00 / 1,000 renders

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 - Website Screenshots

> **HTML to PDF/Image & Screenshot** - A powerful web rendering Actor based on Crawlee and Playwright

### 🎯 Features

- **Multi-Format Output**: PDF, PNG, JPEG, WebP
- **Flexible Input**: URLs or raw HTML strings
- **Advanced View Modes**:
  - `viewport` - Capture exactly what you see
  - `full-page` - **Smart Scroll** technology to capture lazy-loaded content perfectly
  - `selector` - Extract specific DOM elements as vector-rich PDFs or images
  - `readability` - Distraction-free reading mode (Mozilla Readability integration)
- **Page Manipulation**:
  - Remove unwanted elements (ads, cookie banners)
  - Click buttons ("Load More", "I Agree")
  - Inject custom CSS
  - Hide fixed sticky elements
- **Security & Branding**:
  - **PDF Encryption**: Password protect your documents (RC4 128-bit)
  - **Watermarking**: Add text or image watermarks with custom positioning, royalty-free tiling, and transparency
- **Enterprise-Ready**: Proxy support, automatic retries, fingerprint evasion, and PDF merging

### 🚀 Quick Start

#### URL to PDF

```json
{
  "sourceType": "url",
  "startUrls": [{ "url": "https://example.com" }],
  "outputFormat": "pdf",
  "viewMode": "viewport"
}
```

#### HTML to Image

```json
{
  "sourceType": "html",
  "htmlContent": "<h1>Hello World</h1><p>This is a test.</p>",
  "baseUrl": "https://example.com",
  "outputFormat": "png",
  "viewportWidth": 1200,
  "viewportHeight": 630
}
```

#### Full Page Screenshot

```json
{
  "sourceType": "url",
  "startUrls": [{ "url": "https://news.ycombinator.com" }],
  "outputFormat": "png",
  "viewMode": "full-page",
  "smartScroll": true,
  "hideFixedElements": true
}
```

#### Element Extraction

```json
{
  "sourceType": "url",
  "startUrls": [{ "url": "https://example.com" }],
  "outputFormat": "pdf",
  "viewMode": "selector",
  "targetSelector": ".invoice-container"
}
```

### 📋 Input Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `sourceType` | `url` | `html` | `url` | Input source type |
| `startUrls` | array | - | URLs to render |
| `htmlContent` | string | - | Raw HTML to render |
| `baseUrl` | string | - | Base URL for relative paths |
| `outputFormat` | `pdf` | `png` | `jpeg` | `webp` | `pdf` | Output file format |
| `viewMode` | `viewport` | `full-page` | `selector` | `readability` | `viewport` | Capture mode |
| `targetSelector` | string | - | CSS selector for element extraction |
| `viewportWidth` | integer | 1920 | Browser width |
| `viewportHeight` | integer | 1080 | Browser height |
| `scaleFactor` | integer | 2 | Device Scale Factor (DPR) |
| `paperFormat` | `A4` | `A3` | `Letter` | `Legal` | `Tabloid` | `A4` | PDF paper size |
| `printBackground` | boolean | `true` | Include backgrounds in PDF |
| `smartScroll` | boolean | `true` | Enable lazy-load triggering |
| `scrollDelay` | integer | 500 | Wait time after scroll (ms) |
| `waitForSelector` | string | - | Wait for element before capture |
| `removeSelectors` | array | `[]` | Elements to remove |
| `clickSelectors` | array | `[]` | Elements to click |
| `hideFixedElements` | boolean | `true` | Hide sticky navbars |
| `customCss` | string | - | Custom CSS to inject |
| `mergePdfs` | boolean | `false` | Merge all PDFs into one |
| `pdfPassword` | string | - | PDF encryption user/owner password |
| `imageQuality` | integer | 80 | Image compression (1-100) |
| `watermark` | object | - | Watermark configuration (see below) |

#### 💧 Watermark Configuration

The `watermark` object supports the following properties:

| Property | Type | Default | Description |
|----------|------|---------|-------------|
| `type` | `text` | `image` | - | Watermark type |
| `text` | string | - | Text content (for text type) |
| `imageUrl` | string (url) | - | Image URL (for image type) |
| `opacity` | number (0-1) | - | Opacity level |
| `color` | string | - | Text color (e.g. `red`, `#ff0000`, `rgba(...)`) |
| `size` | number | - | Font size (text) or scale % (image) |
| `rotation` | number | - | Rotation in degrees |
| `position` | enum | - | `center`, `top-left`, `top-right`, `bottom-left`, `bottom-right`, `tile` |

### 📤 Output

Results are saved to **Key-Value Store** and metadata to **Dataset**:

```json
{
  "url": "https://example.com",
  "sourceType": "url",
  "outputFormat": "pdf",
  "viewMode": "viewport",
  "fileName": "example_com_2025-12-10T06-30-00-000Z.pdf",
  "fileUrl": "example_com_2025-12-10T06-30-00-000Z.pdf",
  "fileSize": 123456,
  "pageCount": 2,
  "capturedAt": "2025-12-10T06:30:00.000Z"
}
```

### 🍳 Recipes

#### Recipe 1: Invoice Generation

```json
{
  "sourceType": "html",
  "htmlContent": "<html>...invoice template...</html>",
  "baseUrl": "https://yourdomain.com/assets/",
  "outputFormat": "pdf",
  "paperFormat": "A4",
  "printBackground": true
}
```

#### Recipe 2: News Archiving (Ad-Free)

```json
{
  "sourceType": "url",
  "startUrls": [{ "url": "https://news-site.com/article" }],
  "outputFormat": "pdf",
  "viewMode": "full-page",
  "removeSelectors": ["#cookie-banner", ".ad-container", ".newsletter-popup"],
  "hideFixedElements": true
}
```

#### Recipe 3: Social Media Card Generator

```json
{
  "sourceType": "html",
  "htmlContent": "<div style='width:1200px;height:630px;background:linear-gradient(135deg,#667eea,#764ba2);padding:40px;color:white;'><h1>My Article Title</h1></div>",
  "outputFormat": "png",
  "viewportWidth": 1200,
  "viewportHeight": 630
}
```

#### Recipe 4: Secure Document with Watermark

```json
{
  "sourceType": "url",
  "startUrls": [{ "url": "https://example.com/contract" }],
  "outputFormat": "pdf",
  "watermark": {
    "type": "text",
    "text": "CONFIDENTIAL",
    "opacity": 0.3,
    "rotation": -45,
    "position": "center",
    "color": "rgb(255, 0, 0)",
    "size": 50
  },
  "pdfPassword": "secure-password-123"
}
```

#### Recipe 5: Branded Image with Logo Tile

```json
{
  "sourceType": "url",
  "startUrls": [{ "url": "https://example.com" }],
  "outputFormat": "png",
  "watermark": {
    "type": "image",
    "imageUrl": "https://example.com/logo.png",
    "opacity": 0.2,
    "size": 15,
    "position": "tile"
  }
}
```

***

### 💳 Pricing

This Actor uses **pay per event** — you pay for the operations you actually use, not for compute time. A plain URL-to-PDF job only triggers `Render`.

| Event | Price | When it fires |
| :--- | ---: | :--- |
| Render | $0.0070 | Once per page rendered to PDF/PNG/JPEG/WebP |
| Watermark | $0.0020 | Only if you enable watermarking |
| PDF encryption | $0.0030 | Only if you set a password |
| PDF merge | $0.0100 | Once per merged output document |
| Actor start | $0.00005 | Once per run |

**What the free plan gets you:** Apify's free plan includes $5 of platform credit every month, which is about **710 plain renders per month at no cost**. 1,000 renders cost $7; adding watermarks to all of them adds $2.

You are never charged for pages that fail to render. Set **Max total charge** on the run to cap spend.

***

### 🤖 Use with AI agents

This Actor is callable as a tool by any MCP-capable agent — Claude, Cursor, VS Code — or by your
own code, with no wrapper and nothing extra to deploy.

**Connect over MCP**

```
https://mcp.apify.com?tools=autofacts/universal-web-printer
```

In a client that reads an `mcpServers` configuration block:

```json
{
  "mcpServers": {
    "apify": {
      "url": "https://mcp.apify.com?tools=autofacts/universal-web-printer",
      "headers": { "Authorization": "Bearer YOUR_APIFY_TOKEN" }
    }
  }
}
```

The agent reads this Actor's parameters and their descriptions straight from the input
schema, and the hosted server infers the result field types from the dataset schema — so a
model knows what to send and what comes back before it ever calls anything.

**Or call the API directly**

```bash
curl -X POST "https://api.apify.com/v2/acts/autofacts~universal-web-printer/run-sync-get-dataset-items?token=$APIFY_TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"startUrls": [{"url": "https://apify.com/store"}]}'
```

The response body is the dataset records described above.

### 🧰 Other Actors by autofacts

Apify only auto-recommends Actors in the same category, so here are the ones that actually pair with this scraper:

| Actor | What it's for |
| :--- | :--- |
| [Schema Markup Scraper & SEO Auditor](https://apify.com/autofacts/metadata-scraper) | Extract structured data and run a 0–100 SEO audit on the same URL |
| [YouTube Transcript Scraper API](https://apify.com/autofacts/youtube-subtitle-transcript-scraper) | Captions as JSON, SRT, VTT or LLM-ready text |
| [Shopify Scraper](https://apify.com/autofacts/shopify) | Product, variant and collection data from any Shopify store |

All of them: [apify.com/autofacts](https://apify.com/autofacts)

# Actor input Schema

## `sourceType` (type: `string`):

Choose whether to render from URL(s) or raw HTML string

## `startUrls` (type: `array`):

List of URLs to render (required when Source Type is 'url')

## `htmlContent` (type: `string`):

Raw HTML string to render (required when Source Type is 'html')

## `baseUrl` (type: `string`):

Base URL for resolving relative paths in HTML content

## `outputFormat` (type: `string`):

Choose the output file format

## `viewMode` (type: `string`):

How to capture the page: viewport only, full page with smart scroll, specific element, or reading mode

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

Browser viewport width in pixels

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

Browser viewport height in pixels

## `scaleFactor` (type: `integer`):

Device Scale Factor (DPR) for higher quality screenshots (1=Standard, 2=Retina)

## `imageQuality` (type: `integer`):

Quality of the image (1-100) for JPEG/WebP formats

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

PDF paper size

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

Include background colors and images in PDF output

## `mergePdfs` (type: `boolean`):

Merge all generated PDFs into a single file

## `pdfPassword` (type: `string`):

Password to encrypt the PDF output

## `smartScroll` (type: `boolean`):

Enable smart scrolling to trigger lazy-loaded content before capture

## `scrollDelay` (type: `integer`):

Wait time after each scroll step (in milliseconds)

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

Wait for this CSS selector to appear before capturing

## `targetSelector` (type: `string`):

CSS selector for the element to capture (required when View Mode is 'selector')

## `removeSelectors` (type: `array`):

CSS selectors of elements to remove before capture (e.g., cookie banners, ads)

## `clickSelectors` (type: `array`):

CSS selectors of elements to click before capture (e.g., 'Load More' buttons)

## `hideFixedElements` (type: `boolean`):

Hide fixed/sticky positioned elements (navbars, floating buttons) during capture

## `customCss` (type: `string`):

Custom CSS to inject before rendering

## `watermark` (type: `object`):

Add watermark to output files

## `proxyConfiguration` (type: `object`):

Select proxies to be used by your crawler.

## Actor input object example

```json
{
  "sourceType": "url",
  "startUrls": [
    {
      "url": "https://apify.com/store"
    }
  ],
  "outputFormat": "pdf",
  "viewMode": "viewport",
  "viewportWidth": 1920,
  "viewportHeight": 1080,
  "scaleFactor": 2,
  "imageQuality": 80,
  "paperFormat": "A4",
  "printBackground": true,
  "mergePdfs": false,
  "smartScroll": true,
  "scrollDelay": 500,
  "removeSelectors": [],
  "clickSelectors": [],
  "hideFixedElements": true
}
```

# Actor output Schema

## `overview` (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 = {
    "startUrls": [
        {
            "url": "https://apify.com/store"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("autofacts/universal-web-printer").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 = { "startUrls": [{ "url": "https://apify.com/store" }] }

# Run the Actor and wait for it to finish
run = client.actor("autofacts/universal-web-printer").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 '{
  "startUrls": [
    {
      "url": "https://apify.com/store"
    }
  ]
}' |
apify call autofacts/universal-web-printer --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,autofacts/universal-web-printer"
        }
    }
}
```

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/fi6BChInLJciOWmhI/builds/R1ryoaM6WKXvS2X8H/openapi.json
