HTML to PDF
Client call (via BFF)
const response = await fetch('/api/html-to-pdf', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
html: documentHtml,
filename: 'invoice.pdf',
disposition: 'attachment',
orientation: 'portrait',
}),
});
const blob = await response.blob();Inline PDF (restricted)
disposition: 'inline' is allowed only when the request passes host allowlist checks (dev hosts). Configure via handler options in advanced deployments.
Concurrency
Rendering uses a slot semaphore (HTML_TO_PDF_MAX_CONCURRENT). Heavy load: scale horizontally or lower concurrency per instance.
Troubleshooting
| Issue | Check |
|---|---|
| 500 on server | Chromium missing in Docker |
| Empty PDF | HTML must be complete document or valid fragment for Puppeteer |
| Build error on route | Export config inline in pages/api/html-to-pdf/index.ts |
See @sumx/ssr-pdf.