Use Cases
REST API

Direct API Integration

Generate PDFs from any programming language with a simple HTTP call. No SDKs required — just standard REST.

REST Standard API
<1s Response Time
Languages

Quick Start

Generate your first PDF in 30 seconds

terminal
# Simple HTML to PDF conversion
curl -X POST https://api.pdf-mcp.io/htmlToPdf \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1>Hello World</h1><p>Your first PDF</p>",
    "css": "@page { size: A4; margin: 20mm; }",
    "filename": "document.pdf"
  }' \
  --output document.pdf
That's it!

One HTTP call. Standard JSON. PDF output.

  • Send HTML with CSS styling
  • Configure page size and margins
  • Receive PDF binary directly

Works With Any Language

If it can make HTTP requests, it can generate PDFs

Popular

JavaScript / Node.js

Native fetch or axios for server-side PDF generation

  • Native fetch API support
  • Stream responses for large PDFs
  • Express/Fastify middleware ready
  • TypeScript definitions available
Easy Setup

Python

Simple requests library integration for Django, Flask, FastAPI

  • requests/httpx libraries
  • Async support with aiohttp
  • Django/Flask integrations
  • Type hints included
Universal

Any Language

Standard REST API works with any HTTP client

  • Go, Rust, Java, PHP, Ruby
  • cURL for shell scripts
  • OpenAPI spec available
  • No SDK required

What You Can Build

Common patterns for direct API integration

Dynamic Document Generation

Generate PDFs on-demand from your application. Render invoices, receipts, or reports directly from your backend without external dependencies.

Request POST /htmlToPdf with HTML body
Response PDF binary or base64 encoded string
Template-Based Generation

Use your favorite templating engine (Handlebars, Jinja2, EJS) to generate HTML, then convert to PDF. Full control over your document design.

Request Render template → POST to API
Response Pixel-perfect PDF from your template
Batch Processing

Process hundreds of documents efficiently. Loop through your data, generate PDFs in parallel, and handle results with callbacks.

Request Multiple concurrent API calls
Response Individual PDFs or merged document
Webhook Callbacks

For large documents, use async mode with webhook callbacks. Submit your request and receive the PDF URL when generation completes.

Request POST with webhook_url parameter
Response Instant 202 + PDF URL via webhook
PDF Manipulation

Beyond generation: merge multiple PDFs, extract text content, or add watermarks to existing documents using our specialized endpoints.

Request POST /mergePdfs, /extractText, etc.
Response Processed PDF or extracted data
Storage Integration

Store generated PDFs directly to AWS S3 or bring your own bucket (BYOB). More storage providers coming soon. No intermediate file handling required.

Request Include storage configuration
Response Direct URL to stored PDF

API Design

Built for developers, by developers

RESTful Design

Standard REST API with predictable endpoints, HTTP status codes, and JSON responses.

Authentication

Simple Bearer token authentication. One API key for all endpoints.

Rate Limiting

Generous limits with clear headers. Upgrade for higher throughput.

Error Handling

Detailed error messages with codes. Easy debugging in development.

How It Works

Integrate in 4 simple steps

1

Get Your API Key

Sign up and receive your API key instantly. 100 free credits coupon on signup.

2

Build Your HTML

Create HTML with CSS styling. Use any templating engine you prefer.

3

Make API Call

POST to /htmlToPdf endpoint with your HTML and options.

4

Get Your PDF

Receive PDF as base64, download URL, or directly to your storage.

Code Examples

Copy-paste examples for your language

Node.js / JavaScript

generate-pdf.js
// Node.js with native fetch
const response = await fetch('https://api.pdf-mcp.io/htmlToPdf', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.PDF_MCP_API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    html: `
      <html>
        <head>
          <style>
            body { font-family: Arial, sans-serif; }
            .header { color: #333; border-bottom: 2px solid #e11d48; }
          </style>
        </head>
        <body>
          <h1 class="header">Invoice #${invoiceId}</h1>
          <p>Amount: $${amount}</p>
        </body>
      </html>
    `,
    css: '@page { size: A4; margin: 20mm; }',
    filename: `invoice-${invoiceId}.pdf`
  })
});

const pdf = await response.arrayBuffer();
fs.writeFileSync('invoice.pdf', Buffer.from(pdf));

Python

generate_pdf.py
# Python with requests library
import requests
import os

def generate_pdf(html: str, filename: str, css: str = "") -> bytes:
    """Generate PDF from HTML using pdf-mcp API"""
    response = requests.post(
        "https://api.pdf-mcp.io/htmlToPdf",
        headers={
            "Authorization": f"Bearer {os.environ['PDF_MCP_API_KEY']}",
            "Content-Type": "application/json"
        },
        json={
            "html": html,
            "css": css or "@page { size: A4; margin: 20mm; }",
            "filename": filename
        }
    )
    response.raise_for_status()

    with open(filename, 'wb') as f:
        f.write(response.content)

    return response.content

# Usage with Jinja2 template
from jinja2 import Template
template = Template(open('invoice.html').read())
html = template.render(customer=customer, items=items)
generate_pdf(html, 'invoice.pdf')

Go

main.go
// Go with net/http
package main

import (
    "bytes"
    "encoding/json"
    "io"
    "net/http"
    "os"
)

type PDFRequest struct {
    HTML     string `json:"html"`
    CSS      string `json:"css,omitempty"`
    Filename string `json:"filename,omitempty"`
}

func generatePDF(html string) ([]byte, error) {
    payload := PDFRequest{
        HTML:     html,
        CSS:      "@page { size: A4; margin: 20mm; }",
        Filename: "document.pdf",
    }

    body, _ := json.Marshal(payload)
    req, _ := http.NewRequest("POST",
        "https://api.pdf-mcp.io/htmlToPdf",
        bytes.NewBuffer(body))

    req.Header.Set("Authorization",
        "Bearer "+os.Getenv("PDF_MCP_API_KEY"))
    req.Header.Set("Content-Type", "application/json")

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        return nil, err
    }
    defer resp.Body.Close()

    return io.ReadAll(resp.Body)
}

For more languages (PHP, Ruby, Java, Rust, C#) and advanced examples, see our complete API documentation.

Why Direct API?

  • No Dependencies No SDKs to install or maintain. Just HTTP calls.
  • Full Control Handle responses your way. Stream, buffer, or save.
  • Easy Debugging Standard HTTP makes troubleshooting simple.
  • Production Ready Built-in retries, error handling, and rate limits.
api-call.log

[12:45:23] POST /htmlToPdf

[12:45:23] HEADERS Authorization: Bearer ***

[12:45:23] BODY { html: "...", css: "...", filename: "..." }

[12:45:24] STATUS 200 OK

[12:45:24] CONTENT-TYPE application/pdf

[12:45:24] RECEIVED 245.3 KB

Available Endpoints

Everything you need for PDF workflows

POST
/htmlToPdf

Convert HTML to PDF with full CSS support

POST
/mergePdfs

Combine multiple PDF files into one

POST
/extractText

Extract text content from PDF documents

POST
/extractPages

Extract specific pages from a PDF

POST
/pdfToImage

Convert PDF pages to PNG or JPEG images

POST
/pageCount

Get the page count of a PDF document

Start Building Today

Connect your AI Agent via MCP in 30 seconds. 100 free credits coupon on signup.