pdf-mcp Documentation
Browse documentation
Markdown

Quick start

Create an API key and generate your first PDF with curl, Python, or Node.js.

On this page

Generate a PDF with one REST request. If you want to use an AI client, start with MCP setup.

1. Create an account and API key

  1. Open app.pdf-mcp.io, enter your email, and follow the magic link to sign in.
  2. Select the workspace you want the integration to use.
  3. Open API Keys, select Create New API Key, and give the key a name.
  4. Copy the full key immediately; it is shown only once.

Store the key as an environment variable named PDF_MCP_API_KEY in your local shell or secret manager. Keys start with pdfmcp_. Keep them out of source control and browser code.

2. Generate a PDF

Shell
curl --fail-with-body https://api.pdf-mcp.io/htmlToPdf \
  -H "Authorization: Bearer $PDF_MCP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1>Hello, PDF!</h1><p>This is my first document.</p>",
    "storage": { "mode": "memory" }
  }' \
  --output my-first.pdf

On success, open my-first.pdf in your PDF viewer. The explicit memory storage mode returns PDF bytes directly and creates no stored document, regardless of the workspace’s default storage setting.

If curl reports an error, the output file may contain the error response instead of a PDF. Use the troubleshooting table below.

Python

With the requests package installed and PDF_MCP_API_KEY in your environment:

Python
import os
from pathlib import Path

import requests

response = requests.post(
    "https://api.pdf-mcp.io/htmlToPdf",
    headers={"Authorization": f"Bearer {os.environ['PDF_MCP_API_KEY']}"},
    json={
        "html": "<h1>Hello from Python!</h1>",
        "storage": {"mode": "memory"},
    },
    timeout=60,
)
response.raise_for_status()
Path("output.pdf").write_bytes(response.content)

Node.js

Save this example as generate.mjs, then run node generate.mjs with PDF_MCP_API_KEY available in the environment:

JavaScript
import { writeFile } from 'node:fs/promises';

const apiKey = process.env.PDF_MCP_API_KEY;
if (!apiKey) throw new Error('Set PDF_MCP_API_KEY before running this example.');

const response = await fetch('https://api.pdf-mcp.io/htmlToPdf', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${apiKey}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    html: '<h1>Hello from Node.js!</h1>',
    storage: { mode: 'memory' },
  }),
});

if (!response.ok) {
  throw new Error(`PDF request failed (${response.status}): ${await response.text()}`);
}

await writeFile('output.pdf', Buffer.from(await response.arrayBuffer()));

Troubleshooting

ResultWhat to check
401 UnauthorizedSend the Authorization: Bearer … header with your key
402 Payment RequiredCheck the workspace balance and your member credit limit
403 ForbiddenCheck that the key is active and its creator still has the required workspace access
422 Unprocessable EntityCheck the request body against the endpoint reference
Missing images or stylesUse accessible absolute URLs, or set base_url for relative resources

Next steps