Get up and running with the PDF API in under 5 minutes. This guide walks you through creating an account, generating your API key, and making your first PDF.

Step 1: Create Your Account

  1. Visit pdf-mcp.io and click Sign Up
  2. Enter your email address
  3. Check your inbox for a magic link
  4. Click the link to verify your account and sign in

No password required - we use passwordless authentication via magic links for enhanced security.


Step 2: Get Your API Key

Once signed in:

  1. Navigate to API Keys in the dashboard sidebar
  2. Click Create New API Key
  3. Give your key a descriptive name (e.g., “Development”, “Production”)
  4. Copy the generated API key immediately - it won’t be shown again

Your API key will look like this:

pdfmcp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Important: Store your API key securely. Do not commit it to version control or expose it in client-side code.


Step 3: Make Your First Request

Generate a simple PDF from HTML using curl:

curl -X POST https://api.pdf-mcp.io/htmlToPdf \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1>Hello, PDF!</h1><p>This is my first PDF generated via the API.</p>"
  }' \
  --output my-first.pdf

Replace YOUR_API_KEY with the API key you generated in Step 2.

If successful, you’ll have a PDF file named my-first.pdf in your current directory.


Step 4: Verify It Worked

Open my-first.pdf to see your generated document. You should see:

  • A heading “Hello, PDF!”
  • A paragraph with your message

Congratulations! You’ve successfully made your first API request.


What’s Next?

Explore More Endpoints

The API offers much more than HTML to PDF conversion:

EndpointDescription
HTML to PDFConvert HTML content with custom CSS
Text to PDFConvert plain text to PDF
Image to PDFConvert images to PDF documents
PDF to ImageConvert PDF pages to images
Extract TextExtract text content from PDFs
Extract PagesExtract specific pages from PDFs
Merge PDFsCombine multiple PDFs into one
Page CountGet the number of pages in a PDF

Try a More Complex Example

Generate a styled invoice:

curl -X POST https://api.pdf-mcp.io/htmlToPdf \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<!DOCTYPE html><html><head><title>Invoice</title></head><body><h1>Invoice #001</h1><table style=\"width:100%; border-collapse:collapse;\"><tr style=\"background:#f0f0f0;\"><th style=\"border:1px solid #ddd; padding:8px;\">Item</th><th style=\"border:1px solid #ddd; padding:8px;\">Amount</th></tr><tr><td style=\"border:1px solid #ddd; padding:8px;\">API Access</td><td style=\"border:1px solid #ddd; padding:8px;\">$49.00</td></tr></table><p><strong>Total: $49.00</strong></p></body></html>",
    "css": "@page { size: A4; margin: 2cm; }",
    "filename": "invoice-001.pdf"
  }' \
  --output invoice-001.pdf

Use with AI Agents (MCP)

If you’re integrating with AI agents like Claude, check out the MCP Server documentation for seamless AI-powered PDF generation.


Example: Python Integration

import requests

API_KEY = "YOUR_API_KEY"
API_URL = "https://api.pdf-mcp.io/htmlToPdf"

response = requests.post(
    API_URL,
    headers={
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json"
    },
    json={
        "html": "<h1>Hello from Python!</h1>"
    }
)

if response.status_code == 200:
    with open("output.pdf", "wb") as f:
        f.write(response.content)
    print("PDF saved successfully!")
else:
    print(f"Error: {response.status_code}")

Example: Node.js Integration

const fs = require('fs');

const API_KEY = 'YOUR_API_KEY';
const API_URL = 'https://api.pdf-mcp.io/htmlToPdf';

async function generatePdf() {
  const response = await fetch(API_URL, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      html: '<h1>Hello from Node.js!</h1>'
    })
  });

  if (response.ok) {
    const buffer = await response.arrayBuffer();
    fs.writeFileSync('output.pdf', Buffer.from(buffer));
    console.log('PDF saved successfully!');
  } else {
    console.error('Error:', response.status);
  }
}

generatePdf();

Troubleshooting

401 Unauthorized

Your API key is missing or invalid. Make sure:

  • The Authorization header is included
  • The format is Bearer YOUR_API_KEY (with a space after Bearer)
  • Your API key hasn’t been revoked

403 Forbidden

Your API key is valid but lacks permission. This may occur if:

  • Your account has been suspended
  • Your credit balance is zero (purchase more credits)

500 Internal Server Error

The PDF generation failed. Common causes:

  • Invalid HTML syntax
  • External resources that couldn’t be loaded
  • HTML content that’s too complex

PDF is blank or has missing content

  • Check that your HTML is valid
  • Use absolute URLs for images and external resources
  • Or use the base_url parameter for relative URLs

Need Help?

Start building with the PDF API today!