# @embedpdf/snippet 中文文档

规范地址：https://npmcn.com/package/%40embedpdf/snippet/

版本：2\.15\.1
npm 元数据更新时间：2026-09-16T20:51:43.080Z
中文译文更新时间：2026-11-13T14:46:48.763Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40embedpdf/snippet
原文对照：https://npmcn.com/package/%40embedpdf/snippet/?lang=original

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：9.7 MB，364 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：34 个
- 首次发布：2025-12-12T14:58:47.979Z
- 最新版本发布：2026-09-16T20:51:42.880Z
- 近 30 天下载量：1105112（2026-10-14 至 2026-11-12，npm 官方下载统计）
- 已发布版本数：35（近 12 个月 35 个）

## 中文简介

[![EmbedPDF logo](https://www.embedpdf.com/logo-192.png)](https://www.embedpdf.com/)

## 安装

```sh
npm install @embedpdf/snippet
```

也可以使用：`pnpm add @embedpdf/snippet`、`yarn add @embedpdf/snippet`、`bun add @embedpdf/snippet`

## README

[![EmbedPDF logo](https://www.embedpdf.com/logo-192.png)](https://www.embedpdf.com/)

# 嵌入PDF 片断

将 PDF 文件嵌入您网站上的简单方法, 并有一个完整、 随时可用的界面 .

[![Documentation](https://img.shields.io/badge/View%20Docs-0af?style=for-the-badge&labelColor=000000)](https://www.embedpdf.com/docs/snippet/introduction) [![Live Demo](https://img.shields.io/badge/Try%20Live%20Demo-ff1493.svg?style=for-the-badge&labelColor=000000)](https://snippet.embedpdf.com/)

* * *

## 页:1

完全通过,先进的例子,和API的参考文献,在我们的文件网站上:

👉 **[https://www.embedpdf.com/docs/spippet/introduction (中文(简体) )](https://www.embedpdf.com/docs/snippet/introduction)**

* * *

## 导 言

**嵌入PDF 片断** 是一个 _“包括电池”_ 掉入,变成任何 `<div>` 成为专业的PDF阅读器. 没有建设步骤, 没有框架锁 — — 只要复制、粘贴, 你就可以了.

### 为什么选择片段?

-   **完成 UI 退出** - 工具栏、缩略图、搜索、缩放和更多
-   **零建设工具** - 使用简单的HTML网页或与任何联署材料框架并行
-   **30 秒设置** -一个 `<script type="module">` 这是你所需要的
-   **完全可配置** - 用轻量级选项对象调整行为
-   **到处跑** - 现代浏览器、框架、静态网站和CMS

* * *

## QQ 快速安装

添加CDN模块并将其指向容器:

```html
<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>
```

并享受一个满满的观众.

* * *

## 基本使用模式

1.  **集装箱** - 创建查看器将渲染的 DOM 元素 .
2.  **导入** - 负载 `embedpdf.js` 发件人: `type="module"`。 。 。 .
3.  **初始化** - 打电话 `EmbedPDF.init()` 与您的配置.

### 最小示例

```html
<!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>
```

## 许可证

嵌入式PDF 片断是 [麻省理工学院执照](https://github.com/embedpdf/embed-pdf-viewer/blob/main/LICENSE)商业用途是受欢迎的——保持版权标题完整.

## 常见问题

### 如何安装 @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 和提交记录判断。

