@embedpdf/snippet

中文文档
2.15.1发布于 2026/09/17MITTypeScriptES Module近 30 天下载 110.5万
原始使用文档
文档目录7 节
  1. 📚 Documentation
  2. 🚀 Introduction
  3. Why choose the Snippet?
  4. ⚡️ Quick Install
  5. 🛠 Basic Usage Pattern
  6. Minimal Example
  7. 📄 License
EmbedPDF logo

EmbedPDF Snippet

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

Documentation Live Demo


📚 Documentation

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

👉 https://www.embedpdf.com/docs/snippet/introduction


🚀 Introduction

EmbedPDF Snippet is a “batteries‑included” drop‑in that turns any <div> into a professional PDF reader. No build step, no framework lock‑in—just copy, paste, and you’re done.

Why choose the Snippet?

  • Complete UI out‑of‑the‑box – toolbar, thumbnails, search, zoom & more
  • Zero build tooling – works in plain HTML pages or alongside any JS framework
  • 30‑second setup – a single <script type="module"> is all you need
  • Fully configurable – tweak behavior with a lightweight options object
  • Runs everywhere – modern browsers, frameworks, static sites & CMSes

⚡️ Quick Install

Add the CDN module and point it at a container:

<div id="pdf-viewer" style="height: 500px"></div>
<script async type="module">
  import EmbedPDF from 'https://cdn.jsdelivr.net/npm/@embedpdf/snippet@2/dist/embedpdf.js';

  const viewer = EmbedPDF.init({
    type: 'container', // mount strategy
    target: document.getElementById('pdf-viewer'),
    src: 'https://snippet.embedpdf.com/ebook.pdf', // your PDF URL
  });
</script>

That’s it—refresh and enjoy a full‑featured viewer.


🛠 Basic Usage Pattern

  1. Container – create a DOM element where the viewer will render.
  2. Import – load embedpdf.js from the CDN with type="module".
  3. Initialize – call EmbedPDF.init() with your configuration.

Minimal Example

<!DOCTYPE html>
<html>
  <head>
    <title>My PDF Viewer</title>
  </head>
  <body>
    <div id="pdf-viewer" style="height: 100vh"></div>
    <script async type="module">
      import EmbedPDF from 'https://cdn.jsdelivr.net/npm/@embedpdf/snippet@2/dist/embedpdf.js';

      const viewer = EmbedPDF.init({
        type: 'container',
        target: document.getElementById('pdf-viewer'),
        src: 'https://snippet.embedpdf.com/ebook.pdf',
      });
    </script>
  </body>
</html>

📄 License

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

版本与发布记录

@embedpdf/snippet 共发布 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/snippet 的常见问题

如何安装 @embedpdf/snippet?

在项目目录运行 npm install @embedpdf/snippet,或使用 pnpm add / yarn add / bun add。

@embedpdf/snippet 支持 TypeScript 吗?

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

@embedpdf/snippet 支持 ESM 还是 CommonJS?

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

@embedpdf/snippet 可以商用吗?

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

@embedpdf/snippet 的下载量有多少?

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

@embedpdf/snippet 还在维护吗?

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