API Documentation

Everything you need to integrate HTML to PDF conversion into your application

Quick Start

1. Get Your API Token

Sign up and generate your API token from the dashboard.

2. Make Your First Request

curl -X POST https://ezpdf.dev/api/v1/generate-pdf \
  -H "X-API-Key: your_api_token" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1>Hello World</h1><p>This is my first PDF!</p>",
    "options": {
      "format": "A4",
      "orientation": "portrait"
    }
  }' \
  --output document.pdf

Authentication

All API requests require authentication using an API token. Include your token in the request header:

X-API-Key: your_api_token_here

Security: Keep your API token secure. Never expose it in client-side code or public repositories.

Generate PDF

POST /api/v1/generate-pdf

Convert HTML content to a PDF document with customizable options.

Request Body

html required

Type: string

The HTML content to convert to PDF. Maximum size: 5MB.

options optional

Type: object

PDF generation options:

format string

Page format: A4, A3, Letter, Legal (default: A4)

orientation string

Page orientation: portrait or landscape (default: portrait)

margin object

Page margins with units (e.g., "10mm", "1cm", "0.5in")

top - default: 10mm
right - default: 10mm
bottom - default: 10mm
left - default: 10mm
print_background boolean

Include background graphics (default: false)

display_header_footer boolean

Enable custom header/footer (default: false)

header object

Header configuration:

html - HTML template for header
footer object

Footer configuration:

html - HTML template for footer

Example Request

{
  "html": "<html><body><h1>Invoice #1234</h1><p>Total: $99.99</p></body></html>",
  "options": {
    "format": "A4",
    "orientation": "portrait",
    "margin": {
      "top": "20mm",
      "right": "15mm",
      "bottom": "20mm",
      "left": "15mm"
    },
    "print_background": true,
    "display_header_footer": true,
    "header": {
      "html": "<div style='text-align: center; font-size: 10px;'>Company Name</div>"
    },
    "footer": {
      "html": "<div style='text-align: center; font-size: 10px;'>Page <span class='pageNumber'></span></div>"
    }
  }
}

Response

Success (200): Returns the PDF file as application/pdf

Response headers include:

  • X-Request-Id - Unique request identifier
  • X-Duration-Ms - Processing time in milliseconds
  • X-Requests-Remaining - Remaining quota for current period

Error Responses

400 Bad Request

Invalid HTML or options

{
  "code": "ERR_VALIDATION_FAILED",
  "message": "Validation failed",
  "request_id": "req_123"
}
401 Unauthorized

Missing or invalid API key

{
  "code": "ERR_INVALID_API_KEY",
  "message": "Invalid API key"
}
429 Too Many Requests

Quota exceeded for current billing period

{
  "code": "ERR_LIMIT_EXCEEDED",
  "message": "Monthly quota exceeded",
  "usage": {
    "requests_made": 1000,
    "requests_limit": 1000,
    "period_resets_at": "2026-02-01T00:00:00Z"
  }
}
500 Internal Server Error

PDF generation failed

{
  "code": "ERR_GENERATION_FAILED",
  "message": "Failed to generate PDF",
  "request_id": "req_123"
}
504 Gateway Timeout

Request exceeded 60 second timeout

{
  "code": "ERR_TIMEOUT",
  "message": "PDF generation timed out",
  "request_id": "req_123"
}

Rate Limits

Rate limits are based on your subscription plan:

  • Free Plan: 1,000 requests per month
  • Pro Plan: 10,000 requests per month

Check your current usage in the dashboard.

Code Examples

JavaScript / Node.js

const response = await fetch('https://ezpdf.dev/api/v1/generate-pdf', {
  method: 'POST',
  headers: {
    'X-API-Key': 'your_api_token',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    html: '<h1>Hello World</h1>',
    options: {
      format: 'A4',
      orientation: 'portrait'
    }
  })
});

const pdfBuffer = await response.arrayBuffer();
// Save to file or send to client

Python

import requests

response = requests.post(
    'https://ezpdf.dev/api/v1/generate-pdf',
    headers={'X-API-Key': 'your_api_token'},
    json={
        'html': '<h1>Hello World</h1>',
        'options': {
            'format': 'A4',
            'orientation': 'portrait'
        }
    }
)

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

PHP

$ch = curl_init('https://ezpdf.dev/api/v1/generate-pdf');

curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'X-API-Key: your_api_token',
        'Content-Type: application/json'
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'html' => '<h1>Hello World</h1>',
        'options' => [
            'format' => 'A4',
            'orientation' => 'portrait'
        ]
    ])
]);

$pdf = curl_exec($ch);
file_put_contents('document.pdf', $pdf);

Best Practices

Include Print Stylesheets

Use CSS @media print rules to optimize your HTML for PDF output.

Handle Errors Gracefully

Always check the response status and implement retry logic for transient errors.

Monitor Your Usage

Regularly check your quota usage to avoid unexpected rate limiting.

Optimize HTML Size

Keep your HTML content under 5MB. Remove unnecessary whitespace and inline large assets sparingly.

Need Help?

Have questions or need assistance? We're here to help!