Getting Started

Getting Started

LightningPDF provides a simple REST API for generating PDFs from HTML. This guide will get you up and running in minutes.

1. Get Your API Key

  1. Sign up at lightningpdf.dev
  2. Navigate to Settings → API Keys
  3. Click Create API Key and copy your key (starts with lpdf_)

⚠️ Store your API key securely. It won't be shown again.

2. Generate Your First PDF

Using curl

curl -X POST https://lightningpdf.dev/api/v1/pdf/generate \
  -H "Authorization: Bearer lpdf_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1>Hello World</h1><p>My first PDF!</p>"
  }'

Using Python

import requests
import base64

url = "https://lightningpdf.dev/api/v1/pdf/generate"
headers = {
    "Authorization": "Bearer lpdf_your_api_key_here",
    "Content-Type": "application/json"
}
data = {
    "html": "<h1>Hello World</h1><p>My first PDF!</p>"
}

response = requests.post(url, headers=headers, json=data)
result = response.json()

if result["success"]:
    pdf_bytes = base64.b64decode(result["data"]["pdf"])
    with open("output.pdf", "wb") as f:
        f.write(pdf_bytes)
    print(f"PDF generated in {result['data']['generation_time_ms']}ms")

Using Node.js

const axios = require('axios');
const fs = require('fs');

async function generatePDF() {
  const response = await axios.post(
    'https://lightningpdf.dev/api/v1/pdf/generate',
    {
      html: '<h1>Hello World</h1><p>My first PDF!</p>'
    },
    {
      headers: {
        'Authorization': 'Bearer lpdf_your_api_key_here',
        'Content-Type': 'application/json'
      }
    }
  );

  if (response.data.success) {
    const pdfBuffer = Buffer.from(response.data.data.pdf, 'base64');
    fs.writeFileSync('output.pdf', pdfBuffer);
    console.log(`PDF generated in ${response.data.data.generation_time_ms}ms`);
  }
}

generatePDF();

3. Response Format

All successful API responses follow this structure:

{
  "success": true,
  "data": {
    "pdf": "JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PC...",
    "generation_time_ms": 234,
    "engine_used": "chromium"
  }
}
  • pdf: Base64-encoded PDF file
  • generation_time_ms: Generation time in milliseconds
  • engine_used: Rendering engine (native or chromium)

Error Response

{
  "success": false,
  "error": {
    "code": "invalid_html",
    "message": "HTML content is required"
  }
}

4. Check Your Credits

Every API response includes a X-Credits-Remaining header showing your remaining credits:

curl -i https://lightningpdf.dev/api/v1/pdf/generate \
  -H "Authorization: Bearer lpdf_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{"html": "<h1>Test</h1>"}'

# Response headers:
# X-Credits-Remaining: 95

Next Steps