# Convert HTML to PDF

**Use case:** 

Turn an HTML string into a PDF. Paste your markup, such as an invoice, report or certificate, and get a downloadable PDF back. Set the paper size and a base URL for relative links and images, and add a watermark or password. Call it from the API to generate documents from your own templates.

## Input

```json
{
  "sourceType": "html",
  "startUrls": [
    {
      "url": "https://apify.com/store"
    }
  ],
  "htmlContent": "<html><body style=\"font-family:sans-serif\"><h1>Invoice #1042</h1><p>Billed to: Example Ltd</p><table border=\"1\" cellpadding=\"6\"><tr><th>Item</th><th>Amount</th></tr><tr><td>Consulting</td><td>$1,200.00</td></tr><tr><td>Hosting</td><td>$80.00</td></tr></table><p><b>Total: $1,280.00</b></p></body></html>",
  "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
}
```

## Output

```json
{
  "url": {
    "label": "URL",
    "format": "string"
  },
  "outputFormat": {
    "label": "Format",
    "format": "string"
  },
  "viewMode": {
    "label": "Mode",
    "format": "string"
  },
  "fileName": {
    "label": "File",
    "format": "string"
  },
  "fileUrl": {
    "label": "Download",
    "format": "string"
  },
  "fileSize": {
    "label": "Size (bytes)",
    "format": "number"
  },
  "capturedAt": {
    "label": "Captured",
    "format": "string"
  }
}
```

## How it works

### 1. Sign up on Apify or log in

The HTML to PDF & URL to PDF API - Website Screenshots Actor is ready to run with the inputs already set for "Convert HTML to PDF". [Sign up or log in](https://console.apify.com/create-task-from-example/7zYWfQl5dIqDB0Gzy) and you'll land in Apify Console with a copy of this exact task.

### 2. Start the "Convert HTML to PDF" task

The HTML to PDF & URL to PDF API - Website Screenshots Actor will start running based on the input automatically. You can also change all the input fields, like source type, start urls, and more, to match your specific use case.

### 3. Receive the "Convert HTML to PDF" output

Monitor the progress in real time. You will be notified as soon as your dataset is complete and ready for review. Each result includes data such as URL, format, mode, and more.

### 4. Integrate into your workflow

The final output is delivered in JSON, CSV, or Excel format, ready to be plugged into your workflow. You can also [run the "Convert HTML to PDF" task via API](https://apify.com/autofacts/universal-web-printer.md).

## FAQ

### Can I use external images and CSS?

Yes, as long as they are reachable by URL. Set the base URL so relative links in your HTML resolve.

### Can I get an image instead of a PDF?

Yes. Set the output format to PNG, JPEG or WebP.

### How do I generate documents from my own app?

Call the Actor through the Apify API with your HTML in the input, then fetch the file from the download link in the result.

### Where do I get the file?

Each result has a download link. The files are also in the run’s key-value store, and you can fetch them through the Apify API.

### How much does it cost?

You pay per page rendered, plus a small extra for options such as watermarks, passwords or merging. Pages that fail to render are not charged. See the Pricing tab for current rates.

## About this Actor

This example demonstrates how to use [HTML to PDF & URL to PDF API - Website Screenshots](https://apify.com/autofacts/universal-web-printer.md) with a specific input configuration. Visit the [Actor detail page](https://apify.com/autofacts/universal-web-printer.md) to learn more, explore other use cases, and run it yourself.


## How to integrate an Actor?

This Task's input is already configured above. Use it as-is rather than inventing a new one.

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 full API examples (JavaScript, Python, CLI, MCP, OpenAPI), see this Task's Actor page: https://apify.com/autofacts/universal-web-printer.md

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`).
