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
| Scope | pdf: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 limit | 100 requests/hr per API key, on top of the key's overall budget |
| Idempotency | Optional 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 |
| Timeout | The 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.
| Field | Type | Required | Description |
|---|---|---|---|
html | string | One of | The document to render, at most 2 MiB of UTF-8 |
templateId | string | One of | A 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 |
data | object | No | Template 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 |
options | object | No | Rendering and output options (see below) |
Options
| Field | Type | Default | Description |
|---|---|---|---|
size | string | A4 | Paper size: A3, A4, A5, Letter or Legal |
orientation | string | portrait | portrait or landscape |
margins | object | 0 on every side | top, right, bottom, left: a number with mm, cm, in or px (for example "10mm"), at most 100 mm each |
printBackground | boolean | true | Print CSS backgrounds |
headerHtml | string | none | Page header template, at most 16 KiB. See Header and footer |
footerHtml | string | none | Page footer template, at most 16 KiB |
filename | string | document.pdf | 1 to 100 letters, digits, _, . or -; .pdf is added when missing. The name the file downloads as |
remoteImages | boolean | true | Fetch https: images named in the HTML (see Network and scripts). false leaves them out |
returnBase64 | boolean | false | Return the PDF inline as base64 instead of storing it |
urlTtlSeconds | integer | 86400 (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"
}
}
| Field | Type | Description |
|---|---|---|
fileId | string | The stored file's id (stored mode only) |
pdfUrl | string | Time-limited, read-only link to the PDF (stored mode only) |
expiresAt | string | ISO 8601 time the link stops working (stored mode only) |
content | string | The PDF, base64-encoded (base64 mode only) |
contentType | string | Always application/pdf (base64 mode only) |
size | number | PDF size in bytes |
pages | number | Number of pages |
generatedAt | string | ISO 8601 time of generation |
Limits
| Limit | Value | When exceeded |
|---|---|---|
html (and a rendered template) | 2 MiB of UTF-8 | 413 PAYLOAD_TOO_LARGE |
| Request body | About 4.3 MB (Content-Length checked before the body is read) | 413 PAYLOAD_TOO_LARGE |
data | 200 keys, 64 KiB serialised | 400 VALIDATION_ERROR / 413 PAYLOAD_TOO_LARGE |
headerHtml, footerHtml | 16 KiB each | 413 PAYLOAD_TOO_LARGE |
| Render time | 25 seconds | 408 RENDER_TIMEOUT |
| Pages | 100 | 413 OUTPUT_TOO_LARGE |
| PDF size | 20 MiB stored, 3 MiB base64 | 413 OUTPUT_TOO_LARGE |
| Remote images | 20 per render, 2 MiB each, 10 MiB in total, 5 seconds each | The 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 CSSurl()) are fetched by PlatformXe on the page's behalf whenremoteImagesis 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, andsrconimgonly.srcmust be adata:image/png,jpeg,webporgifbase64 URI. style: nourl(,expression(,@import,behavior,-moz-binding,javascript:, CSS comments or backslash escapes.class: letters, digits,_,-and spaces. The classespageNumber,totalPages,date,titleandurlare 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
| Status | Code | Description |
|---|---|---|
| 400 | VALIDATION_ERROR | Invalid 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 |
| 401 | UNAUTHORIZED | Missing or invalid API key |
| 403 | FORBIDDEN | The key lacks pdf:generate, or its organisation is inactive |
| 404 | TEMPLATE_NOT_FOUND | Unknown templateId, or another organisation's template |
| 408 | RENDER_TIMEOUT | The render took longer than 25 seconds. Never stored for idempotency: a retry renders again |
| 409 | CONFLICT | A request with the same x-idempotency-key is still running. Call again with the same key after about 30 seconds |
| 413 | PAYLOAD_TOO_LARGE | html 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 |
| 413 | OUTPUT_TOO_LARGE | More than 100 pages, or a PDF over 20 MiB (stored) or 3 MiB (base64) |
| 429 | RATE_LIMITED | Over the 100/hr tier or the key's budget; wait for Retry-After |
| 503 | STORAGE_UNAVAILABLE | Stored mode only: file storage is unavailable or the upload failed. Retry later, or use returnBase64 |
| 503 | RENDERER_UNAVAILABLE | The renderer could not start. Retry later |
| 500 | INTERNAL_ERROR | Anything 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.