npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pdfjs-embed-viewer

v1.0.77

Published

Pdfjs embed viewer

Readme

PDF.js Embed Viewer

Embed PDF files in Next.js pages with a React component built on PDF.js.

npm version license

Demo — Next.js Integration

The screenshot below shows pdfjs-embed-viewer running in a Next.js 16 App Router application with React 19 and TypeScript. The demo displays a PDF document, an accessible page selector, and Previous / Next / First / Last navigation controls. The PDF canvas scrolls independently while navigation remains visible.

PDF.js Embed Viewer integrated into Next.js, showing a PDF document with page selection and navigation controls

Features

  • Drop-in React component: pass a PDF URL and it renders in your page
  • Built on pdfjs-dist (PDF.js)
  • Written in TypeScript, with bundled type declarations
  • Ships both CommonJS and ES module builds

Requirements

  • React 18+
  • Next.js (or any React 18 app)

Installation

npm install pdfjs-embed-viewer

Usage

"use client"; // required when using the Next.js App Router

import PDFEmbedViewer from "pdfjs-embed-viewer";

export default function Page() {
  return <PDFEmbedViewer url="https://example.com/files/list.pdf" />;
}

The PDF must be reachable from the browser. If it is hosted on another domain, that server needs to allow cross-origin (CORS) requests.

Props

| Prop | Type | Description | | ----- | -------- | -------------------------- | | url | string | URL of the PDF to display |

Development

git clone https://github.com/huachenlihx/pdfjs-embed-viewer.git
cd pdfjs-embed-viewer
npm install
npm run build   # bundles with tsup into dist/

Automated testing

The project uses Vitest, React Testing Library, and jsdom for component unit tests. The PDF.js document loader, browser canvas, and network requests are mocked so tests do not need a live PDF or external server.

npm install
npm test                 # Run tests once
npm run test:watch       # Watch mode
npm run test:coverage    # Generate coverage report

Open the HTML coverage report on macOS with open coverage/index.html after generating it. The generated coverage/ directory is ignored by Git.

The tests cover blob requests, download state, PDF loading and canvas rendering, page selection and navigation, and failure cases. They do not replace real-browser validation with actual PDF documents.

Dependency note: After extracting this update, run npm install to install the new test dependencies and refresh package-lock.json. Commit the regenerated lockfile. react-dom is pinned to React 18 to avoid React 18/19 peer-dependency conflicts.

Contributing

Issues and pull requests are welcome at github.com/huachenlihx/pdfjs-embed-viewer.

Accessibility (WCAG 2.2 AA-oriented)

The viewer includes a named document region and navigation landmark, an accessible page selector, keyboard-operated navigation buttons, visible focus styles, touch-friendly button targets, live announcements for loading and page changes, and error alerts. Automated tests cover several of these accessibility behaviors.

Important limitation: PDF.js currently renders document pages to a canvas. An accessible label for the canvas does not expose the PDF's actual text, reading order, tables, or structure to screen readers. Full document accessibility requires an accessible PDF or a separate tagged/text-based viewing experience. Accordingly, this library does not claim WCAG 2.2 AA conformance.

To review accessibility, navigate by keyboard, test with VoiceOver/NVDA, run axe on a consuming application, and inspect focus visibility at high zoom. See ACCESSIBILITY.md.

React compatibility (React 18 and React 19)

The library declares react and react-dom as peer dependencies supporting React 18.3.1+ and React 19. Local development and testing use React 19; React is not bundled as a runtime dependency of the library. Both React versions must be installed in a consuming application and should be on matching major versions.

Verify the upgrade

npm install
npm ls react react-dom
npm test
npm run typecheck
npm run build

The included package-lock.json is from the previous installation. Run npm install to regenerate it before npm ci, then commit the refreshed lockfile. Test the published package in React 18 and React 19 consuming apps before describing both versions as verified.

The viewer now displays PDF load/render failures as messages rather than silently ignoring them.

License

MIT © Hua Chen