PDFSpark API Documentation

Convert HTML and URLs to pixel-perfect PDFs using Chromium with full JavaScript, CSS3, and web font rendering. The API is completely free — no API keys, no authentication, no signup.

Base URL: https://pdfspark.dev/api/v1

Authentication

No authentication is required. Simply make HTTP requests to the endpoints below. All responses return the PDF binary directly (application/pdf).

POST /pdf/from-html

POST /api/v1/pdf/from-html

Convert raw HTML content to PDF. Supports inline CSS, JavaScript, images via data URIs or external URLs, and web fonts.

Request Body (JSON)

FieldTypeRequiredDescription
html string required The HTML content to convert (max 5MB)
options object optional PDF generation options (see Options)

Example Request

cURL
curl -X POST "https://pdfspark.dev/api/v1/pdf/from-html" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1>Hello World</h1><p>Generated by PDFSpark</p>",
    "options": {
      "format": "A4",
      "margin": { "top": "20mm", "bottom": "20mm" }
    }
  }' \
  -o document.pdf

Response

Returns the PDF file directly as application/pdf binary. Use -o filename.pdf in cURL to save it.

POST /pdf/from-url

POST /api/v1/pdf/from-url

Convert a public webpage to PDF. The URL is loaded in Chromium with full JavaScript execution, just like a real browser.

Request Body (JSON)

FieldTypeRequiredDescription
url string required The URL to convert (must be http/https, no private IPs)
options object optional PDF generation and navigation options (see Options)

Example Request

cURL
curl -X POST "https://pdfspark.dev/api/v1/pdf/from-url" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "options": {
      "format": "A4",
      "printBackground": true,
      "waitUntil": "networkidle"
    }
  }' \
  -o example.pdf

GET /status

GET /api/v1/status

Returns service status and available endpoints.

Response
{
  "service": "PDFSpark",
  "version": "1.0.0",
  "status": "operational",
  "endpoints": [
    { "method": "POST", "path": "/api/v1/pdf/from-html" },
    { "method": "POST", "path": "/api/v1/pdf/from-url" },
    { "method": "GET", "path": "/api/v1/status" }
  ]
}

Page Format Options

OptionTypeDefaultDescription
formatstring"A4"Page format: A3, A4, A5, Letter, Legal, Tabloid
widthstringCustom page width (e.g. "8.5in"). Overrides format.
heightstringCustom page height (e.g. "11in"). Overrides format.
landscapebooleanfalseLandscape orientation
printBackgroundbooleantruePrint background graphics and colors
scalenumber1Scale factor (0.1 to 2.0)
pageRangesstring""Page ranges to print (e.g. "1-3, 5")
preferCSSPageSizebooleanfalseUse CSS @page size instead of format

Margin Options

OptionTypeDefaultDescription
margin.topstring"10mm"Top margin (CSS units: mm, in, px, cm)
margin.rightstring"10mm"Right margin
margin.bottomstring"10mm"Bottom margin
margin.leftstring"10mm"Left margin
OptionTypeDefaultDescription
displayHeaderFooterbooleanfalseEnable header and footer
headerTemplatestring""HTML template for header. Supports: date, title, url, pageNumber, totalPages
footerTemplatestring""HTML template for footer (same classes as header)
Header/footer templates use special CSS classes: <span class="pageNumber"></span>, <span class="totalPages"></span>, <span class="date"></span>, <span class="title"></span>, <span class="url"></span>.
OptionTypeDefaultDescription
waitUntilstring"domcontentloaded"load, domcontentloaded, or networkidle
waitForSelectorstringWait for a CSS selector to appear before PDF generation
delaynumber0Additional delay in ms after page load (max 10000)
timeoutnumber30000Navigation timeout in ms (max 60000)
cssstringCustom CSS to inject before PDF generation
javascriptbooleantrueEnable/disable JavaScript execution
viewport.widthnumber1280Viewport width in pixels
viewport.heightnumber720Viewport height in pixels

Error Codes

StatusMeaning
400Bad Request — Missing or invalid input (HTML, URL, or options)
404Not Found — Endpoint does not exist
413Payload Too Large — HTML exceeds 5MB limit
429Too Many Requests — Rate limit exceeded (20/min)
500Internal Server Error — PDF generation failed
503Service Unavailable — Server busy (too many concurrent requests)

Error responses are JSON:

Error Response
{
  "error": "Missing HTML",
  "message": "Provide an \"html\" field in the request body"
}

Rate Limits

LimitValue
Requests per minute20 per IP address
Max concurrent PDFs5 server-wide
Max HTML size5MB
Navigation timeout60s max
Rate limit headers are included in every response: RateLimit-Limit, RateLimit-Remaining, RateLimit-Reset.

cURL Examples

terminal
# Convert HTML to PDF
curl -X POST "https://pdfspark.dev/api/v1/pdf/from-html" \
  -H "Content-Type: application/json" \
  -d '{"html": "<h1>Invoice #1234</h1><p>Total: $99.00</p>"}' \
  -o invoice.pdf

# Convert URL to PDF (landscape A3)
curl -X POST "https://pdfspark.dev/api/v1/pdf/from-url" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://github.com",
    "options": { "format": "A3", "landscape": true }
  }' \
  -o github.pdf

JavaScript Example

app.js
// Convert HTML to PDF
const response = await fetch('https://pdfspark.dev/api/v1/pdf/from-html', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    html: '<h1>Hello World</h1><p>From PDFSpark</p>',
    options: { format: 'A4', margin: { top: '20mm', bottom: '20mm' } }
  })
});

const blob = await response.blob();
const url = URL.createObjectURL(blob);
window.open(url); // or save with a download link

// Convert URL to PDF
const urlResponse = await fetch('https://pdfspark.dev/api/v1/pdf/from-url', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ url: 'https://example.com' })
});

const pdfBlob = await urlResponse.blob();
// Use pdfBlob as needed...

Python Example

main.py
import requests

# Convert HTML to PDF
response = requests.post(
    'https://pdfspark.dev/api/v1/pdf/from-html',
    json={
        'html': '<h1>Invoice #1234</h1><p>Total: $99.00</p>',
        'options': {'format': 'A4', 'printBackground': True}
    }
)

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

# Convert URL to PDF
response = requests.post(
    'https://pdfspark.dev/api/v1/pdf/from-url',
    json={'url': 'https://example.com'}
)

with open('example.pdf', 'wb') as f:
    f.write(response.content)
Part of the SoftVoyagers Ecosystem