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

pnp-pdf

v1.0.0

Published

Plug and play build of Mozilla's PDF.js library for React.js applications.

Readme

pnp-pdf

Plug and play PDF files using pdf.js. One of the easiest way to render PDF files on browsers.

Installation | HTML example | React.js example

Install npm globally (ignore if already installed):

npm i -g npm

Install the pnp-pdf library:

npm i pnp-pdf

Setup the pnp-pdf library on a JavaScript project

Step 1: Add the HTML file from here https://github.com/abhisekdutta507/pnp-pdf-example.

<body tabindex="0">
  <div id="outerContainer">

    <!-- sidebarContainer -->

    <div id="mainContainer">
      <div class="toolbar"></div>

      <div id="viewerContainer" tabindex="0">
        <div id="viewer" class="pdfViewer"></div>
      </div>
    </div> <!-- mainContainer -->

    <!-- dialogContainer -->

    <!-- editorUndoBar -->

  </div> <!-- outerContainer -->
  <div id="printContainer"></div>
</body>

Step 2: Import the styles

@import 'pnp-pdf/plugin/styles.css';

Step 3: Open the file on browser

import { open } from 'pnp-pdf';

const file = "https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf";

open(file);

Setup the pnp-pdf library on a React.js project

Step 1: Let's create the JSX component like react_pdf_viewer. And only take the JSX.

/* eslint-disable jsx-a11y/aria-role */
/* eslint-disable jsx-a11y/role-has-required-aria-props */
/* eslint-disable jsx-a11y/role-supports-aria-props */
/* eslint-disable jsx-a11y/anchor-is-valid */

import { useEffect } from "react";
import { open } from 'pnp-pdf';
import "pnp-pdf/plugin/styles.css";

/**
 * @param {{
 *    file: string;
 *    style: CSSProperties;
 * }} props 
 * @returns 
 */
export const PDFViewer = ({
  file,
  style,
}) => {
  useEffect(() => {    
    open(file);
  }, [file]);

  return (
    <div id="pdfViewerReactComponent" tabIndex={0} style={style}>
      {/* static JSX template from the react_pdf_viewer.jsx file */}
    </div>
  );
};

export default PDFViewer;

Step 2: Use the JSX component in your project

import { PDFViewer } from "./react_pdf_viewer";

const file = "https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf";

export default function ReactComponent() {
  return (
    <div className="relative w-screen h-screen">
      <PDFViewer file={file} style={{}} />
    </div>
  );
}

Best Practices

  • Make sure the PDFViewer component has some fixed height. By default, width is 100%. If the wrapper does not have a fixed height the script will fail to display the pdf file.
  • It works best when displayed full screen.
  • In real world projects we can not always use it fullscreen. Then, style={{ minWidth: 760 }} will give the best view.

Credits

  1. pdfjs-dist

Source Code

See the package source for more details.