@embedpdf/react-pdf-viewer

中文文档
2.15.1发布于 2026/09/17MITTypeScriptESM + CJS近 30 天下载 92.8万

React component for embedding PDF documents

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

React PDF Viewer

The easiest way to embed PDF files in your React 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/react-pdf-viewer


🚀 Introduction

The @embedpdf/react-pdf-viewer package provides a complete, production-ready PDF viewing experience for React 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.
  • Next.js Ready — Works flawlessly with Next.js App Router and SSR.

📦 Installation

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

🛠 Basic Usage

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

import { PDFViewer } from '@embedpdf/react-pdf-viewer';

export default function App() {
  return (
    <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.

Next.js App Router

The component works seamlessly with Next.js. Since it uses browser APIs (Canvas, WebAssembly), make sure to use it in a Client Component:

'use client';

import { PDFViewer } from '@embedpdf/react-pdf-viewer';

export default function ViewerPage() {
  return (
    <div style={{ height: '100vh' }}>
      <PDFViewer
        config={{
          src: 'https://snippet.embedpdf.com/ebook.pdf',
        }}
      />
    </div>
  );
}

🎨 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: '#9333ea', // Custom brand color (Purple)
        },
      },
    },
  }}
/>

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.

🔌 Accessing the Engine & Registry

For advanced use cases, you can access the underlying PDFium engine or the plugin registry using a ref.

import { useRef } from 'react';
import { PDFViewer, PDFViewerRef } from '@embedpdf/react-pdf-viewer';

function App() {
  const viewerRef = useRef<PDFViewerRef>(null);

  const getMetadata = async () => {
    // Access the plugin registry
    const registry = await viewerRef.current?.registry;
    if (!registry) return;

    // Access the engine directly
    const engine = registry.getEngine();
    console.log('Engine ready:', engine);
  };

  return (
    <>
      <button onClick={getMetadata}>Get Metadata</button>
      <PDFViewer ref={viewerRef} config={{ src: '/doc.pdf' }} />
    </>
  );
}

🧩 Headless Mode

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

Check out our Headless Components which provide hooks 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/react-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/react-pdf-viewer 的常见问题

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

React component for embedding PDF documents

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

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

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

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

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

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

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

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

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

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

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

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