---
title: "Getting Started — Svelte"
description: "Build your own PDF viewer UI with the EmbedPDF headless libraries."
framework: "Svelte"
source: "https://www.cloudpdf.com/docs/headless/svelte/getting-started"
---

# Getting Started

The headless libraries give you the engine and the plugin system — you own
every pixel of the UI. An app depends on two packages: the adapter for your
framework, and an engine.

## Installation

```sh
pnpm add @embedpdf/svelte@next @cloudpdf/engine@next
```

The Svelte adapter mirrors the React surface subpath-for-subpath — the same
verticals, exposed as components and stores.

## Your first viewer

`cloudEngine({ baseUrl })` creates the engine — synchronously and cheaply: it
holds an HTTP client and nothing else, so a module-scope
`const engine = cloudEngine({ baseUrl })` is safe (even under SSR). Hand it to
`<Viewer>`; every open, render, and text call rides HTTPS to your CloudPDF
deployment. This is the whole app:

**`App.svelte`**

```svelte
<script lang="ts">
  import { onMount } from 'svelte';
  import { cloudEngine } from '@cloudpdf/engine';
  import type { DocumentHandle, OpenInput } from '@cloudpdf/engine';
  import PdfPage from './PdfPage.svelte';

  // The Svelte adapter is in progress — this drives the framework-free engine
  // directly: App owns the engine and the document, PdfPage renders one page.
  let doc = $state<DocumentHandle>();

  // The engine is created synchronously and costs nothing until first use —
  // only opening a document does real work.
  const engine = cloudEngine({ baseUrl: 'https://engine.cloudpdf.com' });

  onMount(async () => {
    const ebook: OpenInput = { kind: 'share', shareToken: 'shr_WGj1goAtlNN_fQ5OswPrbJQM' };
    doc = await engine.open(ebook);
  });
</script>

{#if doc}
  <PdfPage {doc} pageNumber={1} />
{:else}
  <p>Opening document…</p>
{/if}
```

**`PdfPage.svelte`**

```svelte
<script lang="ts">
  import { onMount } from 'svelte';
  import type { DocumentHandle } from '@cloudpdf/engine';

  let { doc, pageNumber }: { doc: DocumentHandle; pageNumber: number } = $props();

  let src = $state<string>();

  onMount(async () => {
    const { pages } = await doc.pages.list();
    const page = pages[pageNumber - 1];
    const image = await doc
      .page(page.pageObjectNumber)
      .render.image({ viewport: { kind: 'scale', scale: 1.5 } });
    src = (await image.objectUrl()).url;
  });
</script>

{#if src}
  <img
    {src}
    alt={`Page ${pageNumber}`}
    style="max-width: 100%; border: 1px solid #e6eaf2; border-radius: 8px"
  />
{:else}
  <p>Rendering page…</p>
{/if}
```

Prefer the viewer to own the engine's lifetime — created on mount, destroyed on
unmount? Pass a thunk instead: `engine={() => cloudEngine({ baseUrl })}`. See
the [Engine getting started](https://www.cloudpdf.com/docs/engine/getting-started) for tokens, public
shares, and the ownership model.
