Convert HTML to PDF

The HTML-to-PDF endpoint renders raw HTML markup directly into a PDF document. This is ideal for generating custom invoices, reports, and receipts generated dynamically on your server.

Endpoint

POST https://api.pdfik.net/html-to-pdf

Request Body

ParameterTypeRequiredDescription
htmlstringYesThe raw HTML markup string. Max request payload size is 5 MB.
webhook_urlstringNoOptional callback URL where the job outcome payload will be POSTed. Credentials must not be embedded in the URL (https://user:pass@host is rejected) — configure delivery headers in the dashboard instead.
optionsobjectNoCustom layout, margin, page compression, and watermark options. See PDF Options.
renderobjectNoTimeout and wait selectors. See Browser Options.
testbooleanNoRun the job in test mode: full pipeline, no real render, a sample PDF is returned. Quotas are not debited. Defaults to false.

Request Headers

HeaderRequiredDescription
X-API-KeyYesYour API key (sk_live_...).
Idempotency-KeyNo1-255 characters from A-Z a-z 0-9 _ - . :. Retrying a request with the same key returns the original job instead of creating (and billing) a duplicate. Recommended for retry-after-timeout logic.

Security and Constraints

To ensure platform reliability and security, raw HTML is processed with the following rules:

  • HTML Sanitization: submitted markup passes a strict allowlist of structural and textual tags. <script>, <style>, <link>, <iframe>, <object>, <meta> and similar elements are removed together with their content, and inline event attributes (onload, onclick, …) are dropped.
  • Styling: use inline style="…" attributes — they are preserved and filtered against a CSS property allowlist (layout, typography, colors, borders, spacing; url(…)-capable properties are excluded). <style> blocks and external stylesheets are not supported on this endpoint. If your document depends on full stylesheets, host the page and use /url-to-pdf, which renders it unmodified.
  • Nesting Depth: Markup nested deeper than 256 levels is rejected with 400 Bad Request.
  • External Assets: <img> sources are fetched over HTTP(S) from public hosts (private addresses are blocked at render time).
  • Size Limits: HTML payload size exceeding plan thresholds returns a 413 Payload Too Large error.

Integration Example

1. Basic Request with Custom Styling

curl -X POST https://api.pdfik.net/html-to-pdf \
  -H "X-API-Key: sk_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<html><body><h1 style=\"color: #1e3a8a;\">Invoice #90812</h1><p>Thank you for your business!</p></body></html>",
    "options": {
      "format": "A4",
      "margin": {
        "top": "20mm",
        "bottom": "20mm"
      }
    }
  }'

Response:

{
  "job_id": "8bfa5cc3-09ef-436f-80d4-a0eb867123aa",
  "status": "queued",
  "detail": "Job successfully sent to processing queue."
}

2. Polling and Downloading

The polling flow for html-to-pdf is identical to url-to-pdf. Once the job status updates to done, download the binary directly via GET /jobs/{job_id}/download.