Generate PDF
API reference for generating PDF documents from HTML content.
Generate a PDF document by sending pre-rendered HTML to PlatformXe.
Endpoint
POST /api/v1/pdf/generate
Request body
| Field | Type | Required | Description |
|---|---|---|---|
html | string | Yes | HTML content to render as PDF |
options | object | No | Page rendering options (see below) |
options.margins | object | No | Page margins in CSS units (e.g. "20mm") |
options.margins.top | string | No | Top margin. Default: "10mm" |
options.margins.right | string | No | Right margin. Default: "10mm" |
options.margins.bottom | string | No | Bottom margin. Default: "10mm" |
options.margins.left | string | No | Left margin. Default: "10mm" |
options.orientation | string | No | portrait or landscape. Default: portrait |
options.size | string | No | Paper size: A4, A3, Letter, Legal. Default: A4 |
options.returnBase64 | boolean | No | If true, return base64 content instead of a URL. Default: false |
Response (URL mode)
{
"success": true,
"data": {
"pdfUrl": "https://cdn.platformxe.com/org_123/pdfs/doc_abc123.pdf",
"size": 45230,
"pages": 2,
"generatedAt": "2026-04-05T14:30:00.000Z"
}
}
Response (base64 mode)
{
"success": true,
"data": {
"content": "JVBERi0xLjcKCj...",
"contentType": "application/pdf",
"size": 45230,
"pages": 2,
"generatedAt": "2026-04-05T14:30:00.000Z"
}
}
| Field | Type | Description |
|---|---|---|
pdfUrl | string | URL to download the generated PDF (URL mode only) |
content | string | Base64-encoded PDF content (base64 mode only) |
size | number | File size in bytes |
pages | number | Number of pages in the generated PDF |
generatedAt | string | ISO 8601 timestamp of generation |
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" \
-d '{
"html": "<h1>Invoice #1234</h1><table><tr><td>Widget</td><td>5</td><td>$50.00</td></tr></table><p><strong>Total: $250.00</strong></p>",
"options": {
"margins": {
"top": "20mm",
"bottom": "20mm",
"left": "15mm",
"right": "15mm"
},
"orientation": "portrait",
"size": "A4"
}
}'
SDK
import { PlatformXe } from '@caldera/platformxe-sdk';
const px = new PlatformXe({ apiKey: 'pxk_live_your_api_key_here' });
// Generate with URL output
const result = await px.pdf.generate({
html: '<h1>Invoice #1234</h1><p>Total: $250.00</p>',
options: {
margins: { top: '20mm', bottom: '20mm', left: '15mm', right: '15mm' },
orientation: 'portrait',
size: 'A4',
},
});
console.log(result.data.pdfUrl);
// "https://cdn.platformxe.com/org_123/pdfs/doc_abc123.pdf"
Generate with base64 output
const result = await px.pdf.generate({
html: '<h1>Receipt</h1><p>Payment received. Thank you.</p>',
options: {
returnBase64: true,
size: 'Letter',
},
});
// Decode and save locally
const buffer = Buffer.from(result.data.content, 'base64');
writeFileSync('receipt.pdf', buffer);
Use base64 mode when you need to attach the PDF to an email or process it further without an additional download step.
Error responses
| Code | Description |
|---|---|
BAD_REQUEST | Missing html field or invalid options |
PAYLOAD_TOO_LARGE | HTML content exceeds the 2 MB limit |
FORBIDDEN | Invalid API key |
RATE_LIMITED | Rate limit exceeded for this API key |