PlatformXeDocs
Get API Key

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

FieldTypeRequiredDescription
htmlstringYesHTML content to render as PDF
optionsobjectNoPage rendering options (see below)
options.marginsobjectNoPage margins in CSS units (e.g. "20mm")
options.margins.topstringNoTop margin. Default: "10mm"
options.margins.rightstringNoRight margin. Default: "10mm"
options.margins.bottomstringNoBottom margin. Default: "10mm"
options.margins.leftstringNoLeft margin. Default: "10mm"
options.orientationstringNoportrait or landscape. Default: portrait
options.sizestringNoPaper size: A4, A3, Letter, Legal. Default: A4
options.returnBase64booleanNoIf 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"
  }
}
FieldTypeDescription
pdfUrlstringURL to download the generated PDF (URL mode only)
contentstringBase64-encoded PDF content (base64 mode only)
sizenumberFile size in bytes
pagesnumberNumber of pages in the generated PDF
generatedAtstringISO 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

CodeDescription
BAD_REQUESTMissing html field or invalid options
PAYLOAD_TOO_LARGEHTML content exceeds the 2 MB limit
FORBIDDENInvalid API key
RATE_LIMITEDRate limit exceeded for this API key