Skip to content
Inkoxide

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

Quick start

Install @inkoxide/svelte and render a receipt from a Svelte component.

Edit this page

Svelte templates to PDF with the Inkoxide engine, in Node and in the browser. You write Document, Page, View, Text, Table and the other components in Svelte 5 components, style them with style or Tailwind classes, and get a PDF: the same PDF, byte for byte, as the same document written for @inkoxide/react.

The guide says how Svelte writes each part of a document, and the API.

Part of Inkoxide. Requires Node.js 22 or later and Svelte 5.39 or later; ES modules only.

npm install @inkoxide/svelte svelte
<!-- Receipt.svelte -->
<script lang="ts">
  import { Document, Page, Text, View } from '@inkoxide/svelte';

  let { customer, lines }: { customer: string; lines: { name: string; amount: number }[] } = $props();
  const total = $derived(lines.reduce((sum, l) => sum + l.amount, 0));
</script>

<Document title={`Receipt for ${customer}`}>
  <Page size="A6" class="p-8 text-xs text-gray-900">
    <Text class="text-lg font-bold">Receipt</Text>
    <Text class="mb-4 text-gray-500">for {customer}</Text>
    {#each lines as l (l.name)}
      <View class="flex-row justify-between border-b border-gray-200 py-1.5">
        <Text>{l.name}</Text>
        <Text>${l.amount.toFixed(2)}</Text>
      </View>
    {/each}
    <View class="mt-3 flex-row justify-between font-bold">
      <Text>Total</Text>
      <Text>${total.toFixed(2)}</Text>
    </View>
  </Page>
</Document>
// A SvelteKit endpoint, or any server code built with Vite.
import { renderToBuffer } from '@inkoxide/svelte';

import Receipt from './Receipt.svelte';

const pdf = await renderToBuffer({ component: Receipt, props: { customer: 'Ada Lovelace', lines: [] } });
receipt.pdf
A6 receipt PDF: 'Receipt for Ada Lovelace', three items with prices and a bold total.

Switch to Layout for the boxes the engine laid out.

Drawn by the engine’s debug option, sizes in points.

renderToBuffer, renderToFile and renderToStream take a component with its props, or a component alone. They render it with svelte/server, so the component must be compiled for the server, as SvelteKit and Vite's SSR do. Classes need @inkoxide/tailwind.

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