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

@zonuexe/pdf.js-controller

v1.3.0

Published

provide controller and text layer for pdf.js

Readme

pdf.js-controller

This library provide programming friendly usage of mozilla/pdf.js.

  • Load pdf and show page
  • Display pdf as like presentation
    • Provide controller interface
  • Copy text from pdf
  • Click-able link in pdf

Installation

npm install @zonuexe/pdf.js-controller

Dependencies

Usage

Create Presentation Viewer

The ESM bundle exported by @zonuexe/pdf.js-controller expects the host to provide pdfjs-dist (and the viewer helpers) via an import map. Ensure you load both the upstream viewer stylesheet and this package's styles:

<link rel="stylesheet" href="./node_modules/pdfjs-dist/web/pdf_viewer.css">
<link rel="stylesheet" href="./node_modules/@zonuexe/pdf.js-controller/css/pdf-slide.css">
<script type="importmap">
{
  "imports": {
    "@zonuexe/pdf.js-controller": "./vendor/pdfjs-controller.js",
    "pdfjs-dist": "./node_modules/pdfjs-dist/build/pdf.mjs",
    "pdfjs-dist/web/pdf_viewer.mjs": "./node_modules/pdfjs-dist/web/pdf_viewer.mjs"
  }
}
</script>
<script type="module" src="./build.js" defer></script>

Place pdf.worker.mjs and the cmaps/ directory alongside the module bundle (e.g. ./pdf.worker.mjs, ./cmaps/) and pass those URLs through workerSrc / cMapUrl. The default template generated by the controller renders elements using pdf.js standard class names (textLayer, annotationLayer), so the upstream stylesheet applies without additional overrides.

See example/presentation

import PDFController from '@zonuexe/pdf.js-controller';

const container = document.getElementById('pdf-container');
if (!container) throw new Error('Missing #pdf-container');

const controller = new PDFController({
  container,
  workerSrc: new URL('./pdf.worker.mjs', import.meta.url).toString(),
  cMapUrl: new URL('./cmaps/', import.meta.url).toString(),
  cMapPacked: true
});

const pdfUrl = new URL('./example.pdf', import.meta.url).toString();

controller.loadDocument(pdfUrl)
  .then(() => {
    container.addEventListener(PDFController.Events.before_pdf_rendering, () => {
      // before render
    });
    container.addEventListener(PDFController.Events.after_pdf_rendering, () => {
      // after render
    });

    window.addEventListener('resize', () => {
      void controller.fitItSize();
    });

    document.addEventListener('keydown', (event) => {
      if (event.shiftKey || event.ctrlKey || event.metaKey) {
        return;
      }
      const kc = event.keyCode;
      if (kc === 37 || kc === 40 || kc === 75 || kc === 65) {
        event.preventDefault();
        void controller.prevPage();
      } else if (kc === 38 || kc === 39 || kc === 74 || kc === 83) {
        event.preventDefault();
        void controller.nextPage();
      }
    });
  })
  .catch((error) => {
    console.error(error);
  });

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT