Skip to content
Inkoxide

Search covers every page and heading of the docs. Use ↑ ↓ and ↵.

On a server

Edit this page

renderToBuffer, renderToFile and renderToStream take a component with its props ({ component: Invoice, props: { invoice } }), or a component alone. They render it with svelte/server, so the component must be compiled for the server, as SvelteKit's endpoints and Vite's SSR do; the package ships its components as .svelte files, which the app's build compiles (@sveltejs/vite-plugin-svelte does it for the packages with a svelte export condition).

// src/routes/invoice.pdf/+server.ts
import { renderToBuffer } from '@inkoxide/svelte';

import Invoice from '$lib/pdf/Invoice.svelte';

export async function GET() {
  const pdf = await renderToBuffer({ component: Invoice, props: { invoice: await loadInvoice() } });
  return new Response(pdf, { headers: { 'Content-Type': 'application/pdf' } });
}

Synced from packages/svelte/GUIDE.md in the inkoxide repository.