# URL to PDF (`reinventingai/url-to-pdf`) Actor

Convert webpages, dashboards, invoices, and authenticated app screens into clean PDFs with advanced controls. Supports JavaScript waits, cookies, headers, print settings, PDF/A, PDF/UA, watermarks, attachments, and post-processing. Ideal for reports, archives, and automation workflows.

- **URL**: https://apify.com/reinventingai/url-to-pdf.md
- **Developed by:** [Mark Fulton](https://apify.com/reinventingai) (community)
- **Categories:** Automation, Other, Developer tools
- **Stats:** 4 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $30.00 / 1,000 pdf converteds

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## URL to PDF

Convert webpages, dashboards, reports, invoices, and authenticated app screens into clean downloadable PDFs.

This Apify Actor is built for anyone who needs a reliable **URL to PDF converter** for automation workflows, reporting, archiving, client deliverables, or printable web content. It supports simple one-page exports and more advanced document generation from JavaScript-heavy or logged-in pages.

### Great for

- saving webpages as PDF
- exporting dashboards and analytics views
- generating invoice or contract PDFs from web apps
- archiving articles, landing pages, and reports
- producing compliance-friendly PDFs with metadata, PDF/A, or PDF/UA options

Under the hood it uses [Gotenberg](https://github.com/gotenberg/gotenberg) Chromium and exposes advanced controls in Apify, including:

- page size, margins, landscape, scale, single-page mode
- print backgrounds, screen vs print media emulation, emulated media features
- JavaScript waits (`waitDelay`, `waitForExpression`, `waitForSelector`)
- cookies and custom HTTP headers for authenticated pages
- strict failure rules for HTTP status codes, resource loading, and console exceptions
- header and footer HTML
- document outline, tagged PDFs, PDF/A, PDF/UA, metadata, flattening, encryption
- embeds/attachments
- split, watermark, stamp, and rotate post-processing

### Input

Use `url` for one page or `urls` for several pages in one run.

#### Minimal example

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

#### Backgrounds + JS wait

```json
{
  "url": "https://example.com/dashboard",
  "printBackground": true,
  "waitForSelector": "#app-ready",
  "outputFilename": "dashboard-export"
}
```

#### Authenticated page with cookies

```json
{
  "url": "https://app.example.com/invoice/123",
  "cookies": "[{\"name\":\"session\",\"value\":\"abc\",\"domain\":\"app.example.com\",\"path\":\"/\",\"secure\":true,\"httpOnly\":true}]",
  "printBackground": true
}
```

#### Header/footer HTML

```json
{
  "url": "https://example.com/report",
  "headerHtml": "<html><head><style>html{-webkit-print-color-adjust:exact;font-size:16px;margin:0 20px;}</style></head><body><p>Monthly Report</p></body></html>",
  "footerHtml": "<html><head><style>html{-webkit-print-color-adjust:exact;font-size:16px;margin:0 20px;}</style></head><body><p>Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span></p></body></html>"
}
```

#### Watermark + PDF/A

```json
{
  "url": "https://example.com/contract",
  "watermarkSource": "text",
  "watermarkExpression": "CONFIDENTIAL",
  "watermarkOptions": "{\"opacity\":0.18,\"rotation\":45,\"points\":48}",
  "pdfa": "PDF/A-3b",
  "pdfua": true,
  "generateTaggedPdf": true
}
```

#### Attach files into the PDF

```json
{
  "url": "https://example.com/invoice",
  "embeds": "[{\"url\":\"https://example.com/factur-x.xml\",\"fileName\":\"factur-x.xml\",\"mimeType\":\"text/xml\",\"relationship\":\"Alternative\"}]"
}
```

### Important notes

#### 1. Asset-based features use URLs in this actor

Apify actor inputs do not provide a native file-upload widget.

Because of that, file-backed Gotenberg features are exposed through URL-based inputs:

- `embeds` expects attachment URLs
- `watermarkFileUrl` downloads the watermark image/PDF
- `stampFileUrl` downloads the stamp image/PDF
- `headerHtml` and `footerHtml` accept inline HTML strings

#### 2. Some runs return ZIP instead of PDF

If you use split post-processing and Gotenberg returns multiple files, the actor stores a ZIP in the default key-value store instead of a single PDF.

#### 3. Private-network targets are blocked by default

For safety, the bundled Gotenberg service starts with private-IP access disabled. This actor is meant for public web URLs, authenticated web apps, and downloadable public assets, not intranet SSRF-style access.

### Output

Each successful item includes:

- `requestedUrl`
- `gotenbergTrace`
- `outputType` (`pdf` or `zip`)
- `output.key`
- `output.fileName`
- `output.sizeBytes`
- `output.url`

Generated files are stored in the default key-value store.

### Standby mode

The actor also exposes a lightweight standby API:

- `GET /`
- `GET /convert?url=https://example.com&printBackground=true`
- `POST /convert` with JSON body

# Actor input Schema

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

A single public or authenticated URL to convert into PDF.

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

Optional list of URLs to convert in sequence.

## `outputFilename` (type: `string`):

Optional base filename without extension. If multiple URLs are provided, the actor appends -1, -2, etc.

## `paperWidth` (type: `string`):

Optional paper width like 8.5in, 21cm, or 595pt.

## `paperHeight` (type: `string`):

Optional paper height like 11in, 29.7cm, or 842pt.

## `marginTop` (type: `string`):

Optional top margin like 0.39in or 1cm.

## `marginBottom` (type: `string`):

Optional bottom margin like 0.39in or 1cm.

## `marginLeft` (type: `string`):

Optional left margin like 0.39in or 1cm.

## `marginRight` (type: `string`):

Optional right margin like 0.39in or 1cm.

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

Render in landscape orientation.

## `scale` (type: `number`):

Optional Chromium scale factor, for example 1 or 0.9.

## `singlePage` (type: `boolean`):

Fit the entire output into one very long page.

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

Use page sizes defined in CSS instead of API page size fields.

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

Include background images and colors from the page.

## `omitBackground` (type: `boolean`):

Hide Chromium's default white background for transparent output where supported.

## `emulatedMediaType` (type: `string`):

Optional CSS media type to emulate.

## `emulatedMediaFeatures` (type: `string`):

Optional JSON array like \[{"name":"prefers-color-scheme","value":"dark"}].

## `waitDelay` (type: `string`):

Optional fixed wait like 5s before rendering.

## `waitForExpression` (type: `string`):

Optional JavaScript expression that must evaluate true before rendering.

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

Optional CSS selector that must appear before rendering.

## `cookies` (type: `string`):

Optional JSON array of cookie objects for authenticated pages.

## `extraHttpHeaders` (type: `string`):

Optional JSON object of request headers, including scoped values with ;scope=regex if needed.

## `userAgent` (type: `string`):

Optional custom User-Agent string.

## `failOnHttpStatusCodes` (type: `string`):

Optional JSON array like \[499,599] to fail on matching main page responses.

## `failOnResourceHttpStatusCodes` (type: `string`):

Optional JSON array like \[499,599] to fail when page resources return matching codes.

## `ignoreResourceHttpStatusDomains` (type: `string`):

Optional JSON array of hostnames excluded from resource status code checks.

## `skipNetworkIdleEvent` (type: `boolean`):

Leave enabled to avoid waiting for zero open connections for 500ms.

## `skipNetworkAlmostIdleEvent` (type: `boolean`):

Leave enabled to avoid waiting for two or fewer open connections for 500ms.

## `failOnResourceLoadingFailed` (type: `boolean`):

Fail the conversion if images, CSS, or scripts hit network loading errors.

## `failOnConsoleExceptions` (type: `boolean`):

Fail the conversion when Chromium console exceptions occur.

## `headerHtml` (type: `string`):

Optional full HTML document used as header.html.

## `footerHtml` (type: `string`):

Optional full HTML document used as footer.html.

## `generateDocumentOutline` (type: `boolean`):

Embed PDF bookmarks based on heading tags.

## `metadata` (type: `string`):

Optional XMP metadata JSON object, for example {"Title":"My PDF","Author":"Mark"}.

## `embeds` (type: `string`):

Optional JSON array of attachment objects like \[{"url":"https://.../invoice.xml","fileName":"invoice.xml","mimeType":"text/xml","relationship":"Alternative"}].

## `flatten` (type: `boolean`):

Convert interactive form fields into static page content.

## `nativePageRanges` (type: `string`):

Optional Chromium print ranges like 1-3,5,8-10.

## `splitMode` (type: `string`):

Optional post-processing split mode.

## `splitSpan` (type: `string`):

Split chunk size or explicit page ranges, depending on splitMode.

## `splitUnify` (type: `boolean`):

When splitMode is pages, return one PDF instead of separate files per page range.

## `watermarkSource` (type: `string`):

Optional watermark source type.

## `watermarkExpression` (type: `string`):

Watermark text when watermarkSource is text. For image/pdf sources, provide watermarkFileUrl instead.

## `watermarkPages` (type: `string`):

Optional page ranges to watermark, like 1-3 or 5.

## `watermarkOptions` (type: `string`):

Optional JSON object for watermark options like opacity, color, rotation, font, points, scale, or offset.

## `watermarkFileUrl` (type: `string`):

Required when watermarkSource is image or pdf. Public URL of the watermark asset.

## `watermarkFileName` (type: `string`):

Optional filename override for the uploaded watermark asset.

## `stampSource` (type: `string`):

Optional stamp source type.

## `stampExpression` (type: `string`):

Stamp text when stampSource is text. For image/pdf sources, provide stampFileUrl instead.

## `stampPages` (type: `string`):

Optional page ranges to stamp, like 1-3 or 5.

## `stampOptions` (type: `string`):

Optional JSON object for stamp options like opacity, color, rotation, font, points, scale, or offset.

## `stampFileUrl` (type: `string`):

Required when stampSource is image or pdf. Public URL of the stamp asset.

## `stampFileName` (type: `string`):

Optional filename override for the uploaded stamp asset.

## `rotateAngle` (type: `string`):

Optional rotation angle applied during PDF post-processing.

## `rotatePages` (type: `string`):

Optional page ranges to rotate, like 1-2 or 5.

## `generateTaggedPdf` (type: `boolean`):

Embed Chromium logical structure tags for accessibility.

## `pdfa` (type: `string`):

Optional archival PDF/A conversion mode.

## `pdfua` (type: `boolean`):

Enable PDF/UA accessibility post-processing.

## `userPassword` (type: `string`):

Optional password required to open the PDF.

## `ownerPassword` (type: `string`):

Optional password used to control PDF editing and permissions.

## Actor input object example

```json
{
  "url": "https://example.com",
  "landscape": false,
  "scale": 1,
  "singlePage": false,
  "preferCssPageSize": false,
  "printBackground": false,
  "omitBackground": false,
  "emulatedMediaType": "print",
  "skipNetworkIdleEvent": true,
  "skipNetworkAlmostIdleEvent": true,
  "failOnResourceLoadingFailed": false,
  "failOnConsoleExceptions": false,
  "generateDocumentOutline": false,
  "flatten": false,
  "splitUnify": false,
  "generateTaggedPdf": false,
  "pdfua": false
}
```

# Actor output Schema

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

Structured conversion results returned by the actor dataset.

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

Summary output stored under the OUTPUT record in the default key-value store.

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

Generated PDF or ZIP outputs stored in the default key-value store.

# 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 = {
    "url": "https://example.com"
};

// Run the Actor and wait for it to finish
const run = await client.actor("reinventingai/url-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 = { "url": "https://example.com" }

# Run the Actor and wait for it to finish
run = client.actor("reinventingai/url-to-pdf").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "url": "https://example.com"
}' |
apify call reinventingai/url-to-pdf --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=reinventingai/url-to-pdf",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/USs9ExwwCYPc75JGP/builds/5FtJrEAqR4UGkrQJd/openapi.json
