Skip to content

Output handling

The SDK gives you four ways to handle a rendered PDF: in-memory bytes, a stream, a write-to-disk helper, or a stored document on the server. Pick the one that matches how your code consumes the output.

const pdf = await client.render.pdf({
project: 'billing',
template: 'invoice',
data: { invoiceNumber: 'INV-001' },
});
// pdf: Uint8Array — write, upload, return as-is.

Best for documents that fit comfortably in process memory.

For large PDFs or piping straight to an HTTP response or object store, use pdfStream and let the SDK keep memory bounded.

const stream = await client.render.pdfStream({
project: 'billing',
template: 'invoice',
data: { invoiceNumber: 'INV-001' },
});
// stream: ReadableStream<Uint8Array> — pipe to S3, an HTTP response, or any consumer.

The /node subexport adds a helper that streams bytes directly to disk with bounded memory. Parent directories are created automatically.

import { renderToFile } from '@poli-page/sdk/node';
await renderToFile(
client,
{ project: 'billing', template: 'invoice', data: {} },
'./out.pdf',
);

When you want the PDF to live on Poli Page’s servers (for later download, preview, or thumbnails), use render.document. It returns a descriptor with documentId, presignedPdfUrl, and a downloadPdf() method.

const doc = await client.render.document({
project: 'billing',
template: 'invoice',
data: { invoiceNumber: 'INV-001' },
});
const pdf = await doc.downloadPdf();

presignedPdfUrl has a 15-minute TTL. If it expires, call documents.get(documentId) to refresh.

import { PoliPage } from '@poli-page/sdk';
import { renderToFile } from '@poli-page/sdk/node';
const client = new PoliPage({ apiKey: process.env.POLI_PAGE_API_KEY! });
await renderToFile(
client,
{ project: 'billing', template: 'invoice', data: { invoiceNumber: 'INV-001' } },
'./invoices/INV-001.pdf',
);