# @llamaindex/pdf-viewer

> React PDF viewer for LLM applications

Latest version **1.3.0** (published 2025-02-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @llamaindex/pdf-viewer
pnpm add @llamaindex/pdf-viewer
yarn add @llamaindex/pdf-viewer
bun add @llamaindex/pdf-viewer
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2025-02-24 |
| First published | 2024-05-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 8 |
| Unpacked size | 108.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | yisding, emanuelclferreira, himself_65, marcusschiesser, octopoedi |

## Links

- npm: https://www.npmjs.com/package/@llamaindex/pdf-viewer
- npm.io page: https://npm.io/package/@llamaindex/pdf-viewer

## Dependencies (8)

- [clsx](https://npm.io/package/clsx.md) ^2.0.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [fuse.js](https://npm.io/package/fuse.js.md) ^6.6.2
- [react-pdf](https://npm.io/package/react-pdf.md) ^9.1.0
- [react-window](https://npm.io/package/react-window.md) 1.8.9
- [lodash.debounce](https://npm.io/package/lodash.debounce.md) ^4.0.8
- [@wojtekmaj/react-hooks](https://npm.io/package/@wojtekmaj/react-hooks.md) 1.17.2
- [react-intersection-observer](https://npm.io/package/react-intersection-observer.md) 9.5.1

## Recent versions

- 1.3.0 (latest) — 2025-02-24
- 1.2.0 — 2024-11-01
- 1.1.4 — 2024-10-22
- 1.1.3 — 2024-07-24
- 1.1.1 — 2024-05-16
- 1.1.0 — 2024-05-16

## README

# PDF viewer for RAG applications

PDF viewer component as used by [secinsights](https://github.com/run-llama/sec-insights). Using [react-pdf](https://github.com/wojtekmaj/react-pdf).

## Installation

```bash
npm install @llamaindex/pdf-viewer
```

## Usage

```jsx
import React from 'react';

import '@llamaindex/pdf-viewer/index.css';
import { PDFViewer, PdfFocusProvider } from '@llamaindex/pdf-viewer';

const file = {
  id: 'sample-document',
  url: 'https://d687lz8k56fia.cloudfront.net/sec-edgar-filings/0001045810/10-Q/0001045810-22-000147/filing-details.pdf',
};

function App() {
  return (
    <div className="AppContainer">
      <PdfFocusProvider>
        <PDFViewer file={file} />
      </PdfFocusProvider>
    </div>
  );
}
```

## Custom Styles

```jsx
<PdfFocusProvider>
  <PDFViewer containerClassName="your-container-class-name" file={file} />
</PdfFocusProvider>
```

## Multiple PDF Files

```jsx
<PdfFocusProvider>
  <div className="your-layout-class-name">
    <PDFViewer file={file1} />
    <PDFViewer file={file2} />
    <PDFViewer file={file3} />
  </div>
</PdfFocusProvider>
```

## Next.js

NextJs applications may need to update their configuration to be compatible with react-pdf v9 and pdfjs v4
If you have issues related to canvas, you can add the following to your `next.config.js`:

```diff
module.exports = {
+ webpack: (config) => {
+   config.resolve.alias.canvas = false;

+   return config;
+ },
}
```

Another common issue is: `TypeError: Promise.withResolvers is not a function`
To fix this issue, you need to use dynamic imports for the PDF component (to indicate to NextJs to use it for client-side rendering only).

```diff
- import { PDFViewer, PdfFocusProvider } from "@llamaindex/pdf-viewer";

+ import dynamic from "next/dynamic";

+ // Dynamic imports for client-side rendering only
+ const PDFViewer = dynamic(
+   () => import("@llamaindex/pdf-viewer").then((module) => module.PDFViewer),
+   { ssr: false },
+ );

+ const PdfFocusProvider = dynamic(
+   () =>
+     import("@llamaindex/pdf-viewer").then((module) => module.PdfFocusProvider),
+   { ssr: false },
+ );
```

## Contributing

When making changes to this project, please follow these steps:

1. Make your code changes
2. Create a changeset to document your changes:
   ```bash
   yarn changeset
   ```
3. Commit your changes and the changeset
4. When ready to release a new version:
   ```bash
   yarn new-version
   ```
5. To publish the new version:
   ```bash
   yarn release
   ```

## 🙏 Thanks

Thanks to the developers of the following dependencies that we're using:

- [react-pdf](https://github.com/wojtekmaj/react-pdf)
- @wojtekmaj/react-hooks
- react-window
- react-intersection-observer
- lodash
- fuse.js

---
_Source: https://npm.io/package/@llamaindex/pdf-viewer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
