@embedpdf/svelte-pdf-viewer

中文文档
2.15.1发布于 2026/09/17MITTypeScriptES Module近 30 天下载 1.5万

Svelte component for embedding PDF documents

原始使用文档
文档目录14 节
  1. 📚 Documentation
  2. 🚀 Introduction
  3. Key Features
  4. 📦 Installation
  5. 🛠 Basic Usage
  6. SvelteKit Usage
  7. 🎨 Customization
  8. Theme
  9. Disabling Features
  10. ⚙️ Configuration Options
  11. 🔌 Callbacks & Registry
  12. Available Callbacks
  13. 🧩 Headless Mode
  14. 📄 License
EmbedPDF logo

Svelte PDF Viewer

The easiest way to embed PDF files in your Svelte application with a complete, ready‑to‑use interface.

Documentation Live Demo NPM Version


📚 Documentation

The full walkthrough, advanced examples, and API reference live in our docs site:

👉 https://www.embedpdf.com/svelte-pdf-viewer


🚀 Introduction

The @embedpdf/svelte-pdf-viewer package provides a complete, production-ready PDF viewing experience for Svelte applications.

It is designed to be the fastest way to get a high-quality PDF viewer into your app. You don't need to build toolbars, handle layout logic, or worry about CSS—it just works.

Key Features

  • Ready-to-use UI — Includes a polished toolbar, sidebar, and thumbnails.
  • Responsive — Adapts seamlessly to mobile and desktop screens.
  • Themable — Built-in light/dark modes and support for custom brand colors.
  • Configurable — Easily disable features you don't need (e.g., printing or downloading).
  • TypeScript — Fully typed for a great developer experience.
  • Svelte 4 & 5 — Works with both Svelte 4 and Svelte 5 projects.
  • SvelteKit Ready — Works seamlessly with SSR.

📦 Installation

npm install @embedpdf/svelte-pdf-viewer
# or
pnpm add @embedpdf/svelte-pdf-viewer
# or
yarn add @embedpdf/svelte-pdf-viewer

🛠 Basic Usage

Import the PDFViewer component and render it with a PDF source.

<script>
  import { PDFViewer } from '@embedpdf/svelte-pdf-viewer';
</script>

<div style="height: 100vh;">
  <PDFViewer
    config={{
      src: 'https://snippet.embedpdf.com/ebook.pdf',
      theme: { preference: 'light' },
    }}
  />
</div>

That's it! You now have a fully functional PDF viewer.

SvelteKit Usage

The component works seamlessly with SvelteKit. Since it uses browser APIs (Canvas, WebAssembly), it should be used in a browser context. The component handles this internally, but you can also lazy load it if needed.


🎨 Customization

Theme

The viewer includes a robust theming system. You can set the preference to 'light', 'dark', or 'system', and even override specific colors to match your brand.

<PDFViewer
  config={{
    src: '/document.pdf',
    theme: {
      preference: 'system',
      light: {
        accent: {
          primary: '#ff3e00', // Custom brand color (Orange)
        },
      },
    },
  }}
/>

Disabling Features

Easily customize the UI by disabling features you don't need via the disabledCategories option:

<PDFViewer
  config={{
    src: '/document.pdf',
    disabledCategories: ['annotation', 'print', 'export'],
  }}
/>

Available categories include: zoom, annotation, redaction, document, page, panel, tools, selection, and history.


⚙️ Configuration Options

The config prop accepts the following top-level options:

OptionTypeDescription
srcstringURL or path to the PDF document.
themeobjectTheme configuration (preference, overrides).
tabBar'always' | 'multiple' | 'never'Control visibility of the document tab bar.
disabledCategoriesstring[]Hide specific UI features by category.
i18nobjectConfigure locales and translations.
annotationsobjectConfigure annotation defaults (author, tools).
zoomobjectConfigure default zoom levels and limits.
scrollobjectConfigure scroll direction and logic.

🔌 Callbacks & Registry

Use callback props to access the viewer instance and plugin registry.

<script>
  import { PDFViewer } from '@embedpdf/svelte-pdf-viewer';

  function onready(registry) {
    const engine = registry.getEngine();
    console.log('Engine ready:', engine);
  }
</script>

<PDFViewer config={{ src: '/doc.pdf' }} {onready} />

Available Callbacks

CallbackPayloadDescription
oninitEmbedPdfContainerFired when the viewer container is initialized.
onreadyPluginRegistryFired when the plugin registry is ready.

🧩 Headless Mode

Need complete control over the UI? Building a custom design system?

Check out our Headless Components which provide stores and logic without the UI:

npm install @embedpdf/core @embedpdf/plugin-zoom ...

Read the Headless Documentation for more details.


📄 License

EmbedPDF is MIT licensed. Commercial use is welcome—just keep the copyright headers intact.

版本与发布记录

@embedpdf/svelte-pdf-viewer 共发布 35 个版本,首次发布于 2025/12/12;过去 12 个月发布了 35 个版本。

版本发布日期距今
2.15.1latest2026/09/171 个月前
2.15.02026/08/053 个月前
2.14.42026/06/085 个月前
2.14.32026/05/205 个月前
2.14.22026/04/306 个月前
2.14.12026/04/226 个月前

其他发布通道:next → 2.0.0-next.3。

关于 @embedpdf/svelte-pdf-viewer 的常见问题

@embedpdf/svelte-pdf-viewer 是什么?

Svelte component for embedding PDF documents

如何安装 @embedpdf/svelte-pdf-viewer?

在项目目录运行 npm install @embedpdf/svelte-pdf-viewer,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:svelte(>=4.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@embedpdf/svelte-pdf-viewer 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@embedpdf/svelte-pdf-viewer 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@embedpdf/svelte-pdf-viewer 可以商用吗?

@embedpdf/svelte-pdf-viewer 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@embedpdf/svelte-pdf-viewer 的下载量有多少?

根据 npm 官方下载统计,@embedpdf/svelte-pdf-viewer 在 2026/10/14 – 2026/11/12 这 30 天内被下载 15,432 次,日均约 514 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@embedpdf/svelte-pdf-viewer 还在维护吗?

最新版本 2.15.1 发布于 2026/09/17(1 个月前);至今共发布 35 个版本,其中过去 12 个月发布了 35 个;首次发布于 2025/12/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。