# FileToPDF — Convert documents, HTML & Markdown to PDF (`filetopdf/filetopdf`) Actor

Convert Word, Excel, PowerPoint, images, HTML and Markdown into clean PDFs via the FileToPDF API. Bring your own FileToPDF API key.

- **URL**: https://apify.com/filetopdf/filetopdf.md
- **Developed by:** [Hugo David-Mauduit](https://apify.com/filetopdf) (community)
- **Categories:** Developer tools, Automation
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

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

## 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.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js/docs.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python/docs.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/integrations/mcp.md).

If your project is in a different language, use 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

## FileToPDF — Convert documents, HTML & Markdown to PDF

Convert **Word, Excel, PowerPoint, images and 130+ formats** — plus raw **HTML** and
**Markdown** — into clean PDFs, powered by the [FileToPDF API](https://filetopdf.dev).
The generated PDF is saved to this run's storage as **`output.pdf`**, ready to download.

### What it does

Pick a **mode** and provide the matching input:

| Mode | Input | What happens |
|------|-------|--------------|
| **file** | a public **File URL** | Downloads the file and converts it to PDF. The right engine is chosen automatically by extension (Office → LibreOffice, images → rendered, HTML/Markdown → Chromium, PDF → passed through). |
| **html** | **HTML** (+ optional CSS) | Renders the markup to a pixel-perfect PDF with Chromium. |
| **markdown** | **Markdown** (+ optional CSS) | Renders Markdown to a clean, styled PDF. |

### Bring your own FileToPDF API key

This Actor uses **your** FileToPDF API key — paste it into the **FileToPDF API key**
field (it's a secret input, encrypted at rest). Get one in **one click** at
[filetopdf.dev](https://filetopdf.dev) — no account needed, 10 free conversions. The
Actor first calls the free `GET /account` check to validate your key and log your plan
and remaining credits.

Each successful conversion costs **1 credit** on your FileToPDF account; errors cost
nothing. Max 30 MB; ~50s timeout.

### Output

- **The PDF** is written to the default **key-value store** as **`output.pdf`**
  (`application/pdf`) — download it from the run's **Storage** tab, or via the API:
  `https://api.apify.com/v2/key-value-stores/{STORE_ID}/records/output.pdf`.
- A **dataset** row records the run metadata: `mode`, `source`, `filename`, `pages`,
  `sizeBytes`, `creditsUsed`, `creditsRemaining`, `pdfKey`.

### PDF options (optional)

Layout options — `landscape`, paper size & margins, `scale`, `printBackground`,
`preferCssPageSize`, `nativePageRanges`, `pdfa` (PDF/A-1b/2b/3b), `pdfua`, and PDF
passwords — are available on the **Pro/Scale plan or the free trial**. On Starter/Basic,
using any option returns an upgrade error naming it, so leave them off unless your plan
allows them. Paper size, margins and scale apply to **HTML & Markdown** only; the
source-document password applies to **File** mode only.

### Example input

```json
{
  "apiKey": "sk_live_xxx",
  "mode": "html",
  "html": "<h1>Invoice #1024</h1><p>Thank you for your business.</p>",
  "css": "body { font-family: Georgia, serif; margin: 2cm; }"
}
````

```json
{
  "apiKey": "sk_live_xxx",
  "mode": "file",
  "url": "https://example.com/quarterly-report.docx",
  "landscape": true
}
```

### Links

- FileToPDF — <https://filetopdf.dev>
- API terms — <https://filetopdf.dev/terms>

# Actor input Schema

## `apiKey` (type: `string`):

Your FileToPDF API key (sent as the x-api-key header). Get one free in one click at https://filetopdf.dev — no account needed, 10 free conversions.

## `mode` (type: `string`):

Choose the source type. Fill the matching field below (File URL, HTML, or Markdown).

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

Public http(s) link to the file to convert. The engine is chosen automatically by extension (Office, images, HTML, Markdown, PDF passthrough). Private/internal addresses are rejected.

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

The HTML markup to render. A full document or a snippet both work. Link images/fonts/CSS by full URL.

## `markdown` (type: `string`):

The Markdown content to render. CommonMark with tables, code blocks and images is supported.

## `css` (type: `string`):

Optional CSS. For HTML it is injected into the document head; for Markdown it overrides the default stylesheet.

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

Render in landscape.

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

Default 8.5 (Letter); A4 is 8.27.

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

Default 11 (Letter); A4 is 11.7.

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

Top margin in inches (HTML/Markdown).

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

Bottom margin in inches (HTML/Markdown).

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

Left margin in inches (HTML/Markdown).

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

Right margin in inches (HTML/Markdown).

## `scale` (type: `string`):

e.g. 0.8 to shrink content. Default 1.

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

Print background colors and images (HTML/Markdown).

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

Use the page size declared in the document's CSS @page rule (HTML/Markdown).

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

Limit output to specific pages, e.g. "1-3" or "2,5-7".

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

Produce an ISO-standardised archival PDF.

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

Produce a PDF/UA (accessible) document.

## `password` (type: `string`):

Password to open a protected source document (office files).

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

Encrypt the resulting PDF; this password is required to open it.

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

Restrict editing/printing of the resulting PDF.

## Actor input object example

```json
{
  "mode": "file",
  "url": "https://raw.githubusercontent.com/anthropics/anthropic-sdk-python/main/README.md",
  "landscape": false,
  "printBackground": false,
  "preferCssPageSize": false,
  "pdfa": "",
  "pdfua": false
}
```

# 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://raw.githubusercontent.com/anthropics/anthropic-sdk-python/main/README.md"
};

// Run the Actor and wait for it to finish
const run = await client.actor("filetopdf/filetopdf").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://raw.githubusercontent.com/anthropics/anthropic-sdk-python/main/README.md" }

# Run the Actor and wait for it to finish
run = client.actor("filetopdf/filetopdf").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://raw.githubusercontent.com/anthropics/anthropic-sdk-python/main/README.md"
}' |
apify call filetopdf/filetopdf --silent --output-dataset

```

## MCP server setup

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

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "FileToPDF — Convert documents, HTML & Markdown to PDF",
        "description": "Convert Word, Excel, PowerPoint, images, HTML and Markdown into clean PDFs via the FileToPDF API. Bring your own FileToPDF API key.",
        "version": "0.1",
        "x-build-id": "Hcb1zoIgSLMFibord"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/filetopdf~filetopdf/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-filetopdf-filetopdf",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/filetopdf~filetopdf/runs": {
            "post": {
                "operationId": "runs-sync-filetopdf-filetopdf",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/filetopdf~filetopdf/run-sync": {
            "post": {
                "operationId": "run-sync-filetopdf-filetopdf",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "apiKey",
                    "mode"
                ],
                "properties": {
                    "apiKey": {
                        "title": "FileToPDF API key",
                        "type": "string",
                        "description": "Your FileToPDF API key (sent as the x-api-key header). Get one free in one click at https://filetopdf.dev — no account needed, 10 free conversions."
                    },
                    "mode": {
                        "title": "What to convert",
                        "enum": [
                            "file",
                            "html",
                            "markdown"
                        ],
                        "type": "string",
                        "description": "Choose the source type. Fill the matching field below (File URL, HTML, or Markdown).",
                        "default": "file"
                    },
                    "url": {
                        "title": "File URL  (mode: file)",
                        "type": "string",
                        "description": "Public http(s) link to the file to convert. The engine is chosen automatically by extension (Office, images, HTML, Markdown, PDF passthrough). Private/internal addresses are rejected."
                    },
                    "html": {
                        "title": "HTML  (mode: html)",
                        "type": "string",
                        "description": "The HTML markup to render. A full document or a snippet both work. Link images/fonts/CSS by full URL."
                    },
                    "markdown": {
                        "title": "Markdown  (mode: markdown)",
                        "type": "string",
                        "description": "The Markdown content to render. CommonMark with tables, code blocks and images is supported."
                    },
                    "css": {
                        "title": "CSS  (modes: html, markdown)",
                        "type": "string",
                        "description": "Optional CSS. For HTML it is injected into the document head; for Markdown it overrides the default stylesheet."
                    },
                    "landscape": {
                        "title": "Landscape orientation",
                        "type": "boolean",
                        "description": "Render in landscape.",
                        "default": false
                    },
                    "paperWidth": {
                        "title": "Paper width (inches) — HTML/Markdown",
                        "type": "string",
                        "description": "Default 8.5 (Letter); A4 is 8.27."
                    },
                    "paperHeight": {
                        "title": "Paper height (inches) — HTML/Markdown",
                        "type": "string",
                        "description": "Default 11 (Letter); A4 is 11.7."
                    },
                    "marginTop": {
                        "title": "Margin top (inches) — HTML/Markdown",
                        "type": "string",
                        "description": "Top margin in inches (HTML/Markdown)."
                    },
                    "marginBottom": {
                        "title": "Margin bottom (inches) — HTML/Markdown",
                        "type": "string",
                        "description": "Bottom margin in inches (HTML/Markdown)."
                    },
                    "marginLeft": {
                        "title": "Margin left (inches) — HTML/Markdown",
                        "type": "string",
                        "description": "Left margin in inches (HTML/Markdown)."
                    },
                    "marginRight": {
                        "title": "Margin right (inches) — HTML/Markdown",
                        "type": "string",
                        "description": "Right margin in inches (HTML/Markdown)."
                    },
                    "scale": {
                        "title": "Scale — HTML/Markdown",
                        "type": "string",
                        "description": "e.g. 0.8 to shrink content. Default 1."
                    },
                    "printBackground": {
                        "title": "Print background graphics — HTML/Markdown",
                        "type": "boolean",
                        "description": "Print background colors and images (HTML/Markdown).",
                        "default": false
                    },
                    "preferCssPageSize": {
                        "title": "Prefer CSS @page size — HTML/Markdown",
                        "type": "boolean",
                        "description": "Use the page size declared in the document's CSS @page rule (HTML/Markdown).",
                        "default": false
                    },
                    "nativePageRanges": {
                        "title": "Page ranges",
                        "type": "string",
                        "description": "Limit output to specific pages, e.g. \"1-3\" or \"2,5-7\"."
                    },
                    "pdfa": {
                        "title": "PDF/A archival format",
                        "enum": [
                            "",
                            "PDF/A-1b",
                            "PDF/A-2b",
                            "PDF/A-3b"
                        ],
                        "type": "string",
                        "description": "Produce an ISO-standardised archival PDF.",
                        "default": ""
                    },
                    "pdfua": {
                        "title": "PDF/UA (accessibility)",
                        "type": "boolean",
                        "description": "Produce a PDF/UA (accessible) document.",
                        "default": false
                    },
                    "password": {
                        "title": "Source document password — File mode",
                        "type": "string",
                        "description": "Password to open a protected source document (office files)."
                    },
                    "userPassword": {
                        "title": "Output open password",
                        "type": "string",
                        "description": "Encrypt the resulting PDF; this password is required to open it."
                    },
                    "ownerPassword": {
                        "title": "Output permissions password",
                        "type": "string",
                        "description": "Restrict editing/printing of the resulting PDF."
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
