PlatformXeDocs
Get API Key

Generate PDF

API reference for rendering HTML, or a stored template, to a PDF document.

Render your own HTML, or a stored template filled with your data, to a PDF. By default the PDF is stored as a private file of your organisation and you receive a time-limited, read-only link to it; ask for base64 instead to get the PDF inline.

Endpoint

POST /api/v1/pdf/generate

Scopepdf:generate. It is not one of the scopes a self-registered or portal sign-up key starts with: a key holds it when its scope list names it or holds *, or when it has no scope list (an older key with no scopes)
Rate limit100 requests/hr per API key, on top of the key's overall budget
IdempotencyOptional x-idempotency-key header. A retry with the same key returns the stored answer instead of rendering and storing a second PDF. Base64 answers are not stored, so their retry renders again and is metered again. A 408 RENDER_TIMEOUT is never stored either: a retry with the same key renders again. While the first request is still running, a retry gets 409 CONFLICT: call again with the same key after about 30 seconds
TimeoutThe render has 25 seconds. Allow up to 60 seconds for the whole call (the official SDKs wait 65 seconds)

Request body

Send exactly one of html or templateId.

FieldTypeRequiredDescription
htmlstringOne ofThe document to render, at most 2 MiB of UTF-8
templateIdstringOne ofA stored template: your organisation's, a platform template or a built-in one. Another organisation's template, or an unknown id, is 404 TEMPLATE_NOT_FOUND
dataobjectNoTemplate variables, only with templateId. At most 200 keys of 1 to 64 letters, digits or _ (__proto__, constructor and prototype are refused); values are strings, finite numbers or booleans (sent as text); at most 64 KiB serialised. Every value is HTML-escaped when it is merged into the template
optionsobjectNoRendering and output options (see below)

Options

FieldTypeDefaultDescription
sizestringA4Paper size: A3, A4, A5, Letter or Legal
orientationstringportraitportrait or landscape
marginsobject0 on every sidetop, right, bottom, left: a number with mm, cm, in or px (for example "10mm"), at most 100 mm each
printBackgroundbooleantruePrint CSS backgrounds
headerHtmlstringnonePage header template, at most 16 KiB. See Header and footer
footerHtmlstringnonePage footer template, at most 16 KiB
filenamestringdocument.pdf1 to 100 letters, digits, _, . or -; .pdf is added when missing. The name the file downloads as
remoteImagesbooleantrueFetch https: images named in the HTML (see Network and scripts). false leaves them out
returnBase64booleanfalseReturn the PDF inline as base64 instead of storing it
urlTtlSecondsinteger86400 (24 h)How long the link stays valid, 60 to 604800 (7 days). Stored mode only

Response (stored mode)

{
  "success": true,
  "data": {
    "fileId": "f_ck9x2m4q0000qz8l3v7d1a2b",
    "pdfUrl": "https://files.example.com/generated/org_123/pdf-generate/k3x9.../invoice-1234.pdf?se=2026-11-21T14%3A30%3A00Z&sp=r&sig=...",
    "expiresAt": "2026-11-21T14:30:00.000Z",
    "size": 45230,
    "pages": 2,
    "generatedAt": "2026-11-20T14:30:00.000Z"
  }
}

pdfUrl is a time-limited, read-only link to the stored file, valid until expiresAt; the file downloads as filename. The file stays in your organisation's private storage until you delete it (DELETE /api/v1/storage/media/files/{fileId}), and its bytes count toward your stored-bytes usage. Deleting needs the storage:upload scope: a key that holds only pdf:generate cannot delete the files it generated.

Response (base64 mode)

Base64 output is capped at 3 MiB of PDF; use stored mode for anything larger. Nothing is stored, and a retry renders and is metered again, even under the same idempotency key.

{
  "success": true,
  "data": {
    "content": "JVBERi0xLjcKCj...",
    "contentType": "application/pdf",
    "size": 45230,
    "pages": 2,
    "generatedAt": "2026-11-20T14:30:00.000Z"
  }
}
FieldTypeDescription
fileIdstringThe stored file's id (stored mode only)
pdfUrlstringTime-limited, read-only link to the PDF (stored mode only)
expiresAtstringISO 8601 time the link stops working (stored mode only)
contentstringThe PDF, base64-encoded (base64 mode only)
contentTypestringAlways application/pdf (base64 mode only)
sizenumberPDF size in bytes
pagesnumberNumber of pages
generatedAtstringISO 8601 time of generation

Limits

LimitValueWhen exceeded
html (and a rendered template)2 MiB of UTF-8413 PAYLOAD_TOO_LARGE
Request bodyAbout 4.3 MB (Content-Length checked before the body is read)413 PAYLOAD_TOO_LARGE
data200 keys, 64 KiB serialised400 VALIDATION_ERROR / 413 PAYLOAD_TOO_LARGE
headerHtml, footerHtml16 KiB each413 PAYLOAD_TOO_LARGE
Render time25 seconds408 RENDER_TIMEOUT
Pages100413 OUTPUT_TOO_LARGE
PDF size20 MiB stored, 3 MiB base64413 OUTPUT_TOO_LARGE
Remote images20 per render, 2 MiB each, 10 MiB in total, 5 seconds eachThe image is left out

Network and scripts

The PDF is rendered by a headless browser engine that runs no JavaScript and reaches no network on its own:

  • Scripts do not run. Build the document on your side; charts and computed values must already be in the HTML.
  • The page loads nothing itself: stylesheets, fonts, frames, objects and links to other documents are not fetched, and the page cannot navigate away (a meta refresh is ignored). Inline your CSS and use data: URIs for fonts.
  • https: images (<img> and CSS url()) are fetched by PlatformXe on the page's behalf when remoteImages is on: public addresses only, no redirects followed, PNG, JPEG, WebP or GIF only (checked by content, not by the declared type), within the limits above. An image that fails any check is left out; the render still succeeds. data: images always work.
  • A Content-Security-Policy is placed in front of your HTML as a second fence.

Each render runs in its own isolated browser context, which is discarded afterwards. The renderer carries few fonts: it includes Noto Sans (regular and bold, which covers ₦). For any other typeface, embed it with @font-face and a data: URI.

Header and footer

headerHtml and footerHtml are printed on every page. They are checked against an allow-list, and anything outside it is refused with 400 VALIDATION_ERROR (never silently removed):

  • Elements: div, span, p, br, b, strong, i, em, small, img.
  • Attributes: class, style, and src on img only. src must be a data:image/png, jpeg, webp or gif base64 URI.
  • style: no url(, expression(, @import, behavior, -moz-binding, javascript:, CSS comments or backslash escapes.
  • class: letters, digits, _, - and spaces. The classes pageNumber, totalPages, date, title and url are filled in by the renderer.

Header and footer templates do not inherit the page's CSS: give them their own font size (for example style="font-size:8px"), and leave room for them with margins. When only one is given, the other is printed empty.

Examples

curl

curl -X POST https://api.platformxe.com/api/v1/pdf/generate \
  -H "Content-Type: application/json" \
  -H "x-api-key: pxk_live_your_api_key_here" \
  -H "x-idempotency-key: invoice-1234-v1" \
  -d '{
    "html": "<h1>Invoice #1234</h1><table><tr><td>Pro plan</td><td>₦99,000.00</td></tr></table><p><strong>Total: ₦106,425.00</strong></p>",
    "options": {
      "size": "A4",
      "margins": { "top": "20mm", "bottom": "20mm", "left": "15mm", "right": "15mm" },
      "footerHtml": "<div style=\"font-size:8px\">Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span></div>",
      "filename": "invoice-1234.pdf"
    }
  }'

From a stored template

curl -X POST https://api.platformxe.com/api/v1/pdf/generate \
  -H "Content-Type: application/json" \
  -H "x-api-key: pxk_live_your_api_key_here" \
  -d '{
    "templateId": "tpl_abc",
    "data": { "customerName": "Ada", "total": "₦106,425.00" },
    "options": { "urlTtlSeconds": 3600 }
  }'

TypeScript SDK

import { PlatformXeClient } from '@caldera/platformxe-sdk';

const px = new PlatformXeClient({ apiKey: 'pxk_live_your_api_key_here' });

const result = await px.pdf.generate(
  {
    html: '<h1>Invoice #1234</h1><p>Total: ₦106,425.00</p>',
    options: { size: 'A4', margins: { top: '20mm', bottom: '20mm' }, filename: 'invoice-1234.pdf' },
  },
  { idempotencyKey: 'invoice-1234-v1' },
);

if ('pdfUrl' in result) {
  console.log(result.pdfUrl, result.expiresAt);
}

Base64 output

const result = await px.pdf.generate({
  html: '<h1>Receipt</h1><p>Payment received. Thank you.</p>',
  options: { returnBase64: true, size: 'Letter' },
});

writeFileSync('receipt.pdf', Buffer.from(result.content, 'base64'));

Use base64 mode for a small PDF you attach to an email or process at once; nothing is stored. Use stored mode (the default) for anything you link to or that may be over 3 MiB.

Python SDK

result = px.pdf.generate(
    "<h1>Invoice #1234</h1><p>Total: ₦106,425.00</p>",
    options={"size": "A4", "filename": "invoice-1234.pdf"},
    idempotency_key="invoice-1234-v1",
)
print(result["pdfUrl"], result["expiresAt"])

Go SDK

result, err := client.Pdf.Generate(platformxe.GeneratePdfInput{
    HTML:    "<h1>Invoice #1234</h1><p>Total: ₦106,425.00</p>",
    Options: &platformxe.GeneratePdfOptions{Size: "A4", Filename: "invoice-1234.pdf"},
}, &platformxe.GeneratePdfCallOptions{IdempotencyKey: "invoice-1234-v1"})
if err != nil {
    log.Fatal(err)
}
fmt.Println(result.PdfURL, result.ExpiresAt)

Error responses

StatusCodeDescription
400VALIDATION_ERRORInvalid JSON; neither or both of html and templateId; data with html; a bad data key or value; a bad option; a header or footer outside the allow-list
401UNAUTHORIZEDMissing or invalid API key
403FORBIDDENThe key lacks pdf:generate, or its organisation is inactive
404TEMPLATE_NOT_FOUNDUnknown templateId, or another organisation's template
408RENDER_TIMEOUTThe render took longer than 25 seconds. Never stored for idempotency: a retry renders again
409CONFLICTA request with the same x-idempotency-key is still running. Call again with the same key after about 30 seconds
413PAYLOAD_TOO_LARGEhtml or the rendered template over 2 MiB, the request body over the size limit, data over 64 KiB, or a header or footer over 16 KiB
413OUTPUT_TOO_LARGEMore than 100 pages, or a PDF over 20 MiB (stored) or 3 MiB (base64)
429RATE_LIMITEDOver the 100/hr tier or the key's budget; wait for Retry-After
503STORAGE_UNAVAILABLEStored mode only: file storage is unavailable or the upload failed. Retry later, or use returnBase64
503RENDERER_UNAVAILABLEThe renderer could not start. Retry later
500INTERNAL_ERRORAnything else (a fixed message; details are never returned)

Generating a PDF is metered as one pdf.render per delivered PDF (none for a refused or failed render), and a stored PDF's bytes are metered as stored storage.