Direct API Integration
Generate PDFs from any programming language with a simple HTTP call. No SDKs required — just standard REST.
Quick Start
Generate your first PDF in 30 seconds
# 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 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
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
Python
Simple requests library integration for Django, Flask, FastAPI
-
requests/httpx libraries -
Async support with aiohttp -
Django/Flask integrations -
Type hints included
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
Generate PDFs on-demand from your application. Render invoices, receipts, or reports directly from your backend without external dependencies.
Use your favorite templating engine (Handlebars, Jinja2, EJS) to generate HTML, then convert to PDF. Full control over your document design.
Process hundreds of documents efficiently. Loop through your data, generate PDFs in parallel, and handle results with callbacks.
For large documents, use async mode with webhook callbacks. Submit your request and receive the PDF URL when generation completes.
Beyond generation: merge multiple PDFs, extract text content, or add watermarks to existing documents using our specialized endpoints.
Store generated PDFs directly to AWS S3 or bring your own bucket (BYOB). More storage providers coming soon. No intermediate file handling required.
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
Get Your API Key
Sign up and receive your API key instantly. 100 free credits coupon on signup.
Build Your HTML
Create HTML with CSS styling. Use any templating engine you prefer.
Make API Call
POST to /htmlToPdf endpoint with your HTML and options.
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
// 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
# 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
// 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.
[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
Convert HTML to PDF with full CSS support
Combine multiple PDF files into one
Extract text content from PDF documents
Extract specific pages from a PDF
Convert PDF pages to PNG or JPEG images
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.