# PDF Generator: Markdown & HTML to PDF and Word (DOCX) (`tudorlane/html-markdown-to-pdf`) Actor

Turn Markdown or HTML into downloadable PDF, Word (DOCX) or HTML files with report, invoice and letter styles, page numbers, headers and A4/Letter sizes. Built for AI agents that write documents.

- **URL**: https://apify.com/tudorlane/html-markdown-to-pdf.md
- **Developed by:** [Tudor Lane](https://apify.com/tudorlane) (community)
- **Categories:** Developer tools
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$5.00 / 1,000 document generateds

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

## PDF Generator: Markdown & HTML to PDF and Word (DOCX)

### Use when…

- You need Markdown or HTML turned into a PDF or Word (DOCX) file.
- An agent must generate a report, invoice layout or printable doc from structured text.
- You want a downloadable document artifact from a simple text input.

### Try this input

Copy-paste this JSON as the Actor input (it matches a successful run / the default schema):

```json
{
  "requests": [
    {
      "markdown": "# Quarterly Report\n\nRevenue grew **12%**.\n\n| Region | Sales |\n|---|---|\n| UK | £1.2m |\n| US | $2.4m |\n\n- Point one\n- Point two",
      "template": "report",
      "title": "Q3 Report",
      "formats": [
        "pdf",
        "docx"
      ]
    },
    {
      "html": "<h1>Invoice #1001</h1><p>Bill to: Acme Ltd</p><table><tr><th>Item</th><th>Amount</th></tr><tr><td>Consulting</td><td>£500.00</td></tr></table>",
      "template": "invoice",
      "formats": [
        "pdf"
      ]
    }
  ]
}
```

### Sample output (real run 2026-10-25)

One dataset item, shortened:

```json
{
  "title": "Invoice #1001",
  "template": "invoice",
  "files": {
    "pdf": {
      "url": "https://api.apify.com/v2/key-value-stores/UA3Tbg9Kc06M8Zcwi/records/Invoice-1001-21b7988d.pdf?signature=15yKTRr1LpTWxKrOmQUO7",
      "key": "Invoice-1001-21b7988d.pdf",
      "bytes": 8540,
      "pages": 1
    }
  },
  "pdf_url": "https://api.apify.com/v2/key-value-stores/UA3Tbg9Kc06M8Zcwi/records/Invoice-1001-21b7988d.pdf?signature=15yKTRr1LpTWxKrOmQUO7",
  "docx_url": null,
  "pages": 1,
  "ms": 1332,
  "error": null
}
```

Agents can write documents but can't hand over a file. This turns their Markdown or HTML into a real PDF or Word document with a download link.

- Markdown (tables, code blocks, lists) or raw HTML in, PDF / DOCX / HTML out, in one call
- Templates: plain, report, invoice, letter; add your own `css`
- Page numbers (Page X of Y), header text, A4 / Letter / Legal / A5, title and author metadata
- Remote images over public https are embedded; local files and private addresses are blocked
- No browser needed (WeasyPrint), so it's fast and cheap; files are kept in the run's key-value store

### Input

```json
{"requests": [{"markdown": "# Proposal\n\nPrepared for **Acme**.\n\n| Item | Price |\n|---|---|\n| Setup | £900 |", "template": "report", "formats": ["pdf", "docx"], "header": "Confidential"}]}
```

Send many items in `requests` per run (cheaper and faster than one run each). Settings outside `requests` apply to every item.

### Pricing

Pay per event: **$0.005 per document generated** (one document generated (all requested formats)). Rows with errors are not charged. No subscription.

### Output

One dataset row per request. Errors come back as a row with `error` set, so a batch never fails because of one bad item.

### Use from AI agents (MCP)

Add it to any MCP client via `https://mcp.apify.com?actors=tudorlane/html-markdown-to-pdf`, or call the Apify API / run-sync endpoint.

### Sources and licences

WeasyPrint (BSD), Python-Markdown (BSD), python-docx (MIT), htmldocx (MIT), DejaVu and Liberation fonts. No external data.

**Search terms:** PDF generator, HTML to PDF, markdown to PDF, PDF API, DOCX generator, invoice PDF, report PDF

### Sample output (real run with the default input, 25 Oct 2026)

| Title | Template | Files made | Pages | Time |
|---|---|---|---|---|
| Invoice #1001 | invoice | PDF | 1 | 0.8 s |
| Q3 Report | report | PDF + Word (DOCX) | 1 | 1.4 s |

### Use cases

1. Generate invoices or reports from HTML
2. Turn AI-written markdown into PDF or Word
3. Agents: make a shareable document in one call
4. Batch document export

### Limits & failure modes

- Complex CSS/JavaScript layouts may render differently from a browser
- Output files stored in the run's key-value store
- Complex CSS/JS layouts may not render exactly like a browser print.
- Very large inputs can hit memory/time limits; split documents if needed.
- Failed conversions return an error and are not charged.

# Actor input Schema

## `requests` (type: `array`):

Each item: {"markdown": "# Title..."} or {"html": "<h1>...</h1>"}, plus optional formats \[pdf, docx, html], template (plain, report, invoice, letter), title, author, header, page_size, css, filename. Max 200. Errors are not charged.

## Actor input object example

```json
{
  "requests": [
    {
      "markdown": "# Quarterly Report\n\nRevenue grew **12%**.\n\n| Region | Sales |\n|---|---|\n| UK | £1.2m |\n| US | $2.4m |\n\n- Point one\n- Point two",
      "template": "report",
      "title": "Q3 Report",
      "formats": [
        "pdf",
        "docx"
      ]
    },
    {
      "html": "<h1>Invoice #1001</h1><p>Bill to: Acme Ltd</p><table><tr><th>Item</th><th>Amount</th></tr><tr><td>Consulting</td><td>£500.00</td></tr></table>",
      "template": "invoice",
      "formats": [
        "pdf"
      ]
    }
  ]
}
```

# Actor output Schema

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

One item per request.

## `dataset` (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 = {
    "requests": [
        {
            "markdown": "# Quarterly Report\n\nRevenue grew **12%**.\n\n| Region | Sales |\n|---|---|\n| UK | £1.2m |\n| US | $2.4m |\n\n- Point one\n- Point two",
            "template": "report",
            "title": "Q3 Report",
            "formats": [
                "pdf",
                "docx"
            ]
        },
        {
            "html": "<h1>Invoice #1001</h1><p>Bill to: Acme Ltd</p><table><tr><th>Item</th><th>Amount</th></tr><tr><td>Consulting</td><td>£500.00</td></tr></table>",
            "template": "invoice",
            "formats": [
                "pdf"
            ]
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("tudorlane/html-markdown-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 = { "requests": [
        {
            "markdown": """# Quarterly Report

Revenue grew **12%**.

| Region | Sales |
|---|---|
| UK | £1.2m |
| US | $2.4m |

- Point one
- Point two""",
            "template": "report",
            "title": "Q3 Report",
            "formats": [
                "pdf",
                "docx",
            ],
        },
        {
            "html": "<h1>Invoice #1001</h1><p>Bill to: Acme Ltd</p><table><tr><th>Item</th><th>Amount</th></tr><tr><td>Consulting</td><td>£500.00</td></tr></table>",
            "template": "invoice",
            "formats": ["pdf"],
        },
    ] }

# Run the Actor and wait for it to finish
run = client.actor("tudorlane/html-markdown-to-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 '{
  "requests": [
    {
      "markdown": "# Quarterly Report\\n\\nRevenue grew **12%**.\\n\\n| Region | Sales |\\n|---|---|\\n| UK | £1.2m |\\n| US | $2.4m |\\n\\n- Point one\\n- Point two",
      "template": "report",
      "title": "Q3 Report",
      "formats": [
        "pdf",
        "docx"
      ]
    },
    {
      "html": "<h1>Invoice #1001</h1><p>Bill to: Acme Ltd</p><table><tr><th>Item</th><th>Amount</th></tr><tr><td>Consulting</td><td>£500.00</td></tr></table>",
      "template": "invoice",
      "formats": [
        "pdf"
      ]
    }
  ]
}' |
apify call tudorlane/html-markdown-to-pdf --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,tudorlane/html-markdown-to-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/9oUc2QzZ2dbWn1mDs/builds/hxjEKGxkXg0YsoGTa/openapi.json
