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

pdf-web-viewer

v1.1.3

Published

PDF Web Viewer is a lightweight wrapper around the official PDF.js viewer for simple PDF previews in web apps. The project exposes a small API to create a viewer instance and mount it into your page.

Readme

📄 PDF Web Viewer

PDF Web Viewer is a lightweight wrapper around the official PDF.js viewer for simple PDF previews in web apps. The project exposes a small API to create a viewer instance and mount it into your page.

🚀 Quick Start

  1. Add a container to your HTML document where the viewer will be mounted:

    <div class="pdf-container"></div>
  2. Install the package (if published to a registry):

    pnpm add pdf-web-viewer
    # or
    npm install pdf-web-viewer
    # or
    yarn add pdf-web-viewer
  3. Use the library according to your project type.

    ESM Projects

    import { create } from 'pdf-web-viewer'
    
    const container = document.querySelector('div.pdf-container')
    
    // Option A: relative path (resolved against location.origin)
    const viewer = create('/assets/sample.pdf', { width: '800px', height: '600px' })
    viewer.mount(container)
    
    // Option B: absolute URL
    const viewer = create('https://example.com/files/document.pdf', {
      width: '100%',
      height: '100%',
    })
    viewer.mount(container)

    Non-ESM Projects

    If you build a UMD bundle that exposes a PdfViewer global, use it like:

    <script src="node_modules/pdf-web-viewer/dist/index.umd.js"></script>
    <script>
      window.onload = function () {
        // Accepts a relative path or an absolute URL (http/https)
        const viewer = PdfViewer.create('/assets/sample.pdf')
        viewer.mount(document.querySelector('div.pdf-container'))
      }
    </script>

▶️ Live Demo

Try it instantly — no setup required:

Open in CodeSandbox →

🎥 Gif Demo

Demo

🛠️ API Overview

create(filePath: string, options?: { width?: string; height?: string; displayPagePanel?: boolean }): PdfWebViewer

Creates a viewer instance and returns it. The instance exposes the mount and setFile methods.

  • filePath (string): Path or URL of the PDF file to display. Two formats are accepted:

    • Relative path — e.g. '/assets/sample.pdf'. Resolved to an absolute URL using location.origin.
    • Absolute URL — e.g. 'https://example.com/files/document.pdf'. Used directly (URL-encoded before being passed to the viewer).

    The value must end with .pdf (case-insensitive), otherwise an Error is thrown.

  • options (optional):

    • width (string) — width of the PDF viewer; default: 100%.
    • height (string) — height of the PDF viewer; default: 100%.
    • displayPagePanel (boolean) — when true, opens the viewer with the thumbnail panel visible; default: false.

Methods

  • mount(targetElement: HTMLElement): void

    • Adds the PDF viewer into targetElement. Throws an Error if targetElement is not provided.
  • setFile(filePath: string): void

    • Updates the viewer to load a new PDF. Accepts the same relative paths and absolute URLs (http/https) as create. The filePath must be provided and must end with .pdf, otherwise an Error is thrown.

Error handling

  • create and setFile will throw an Error if the provided filePath is missing or does not end with .pdf.
  • mount will throw if a valid mount target is not provided.

Note on CORS: when using absolute URLs pointing to a different origin, the remote server must allow cross-origin requests, otherwise the browser will block the PDF from loading.

📚 Additional resources

For advanced usage and detailed API references, see the official PDF.js documentation.

🙏 Acknowledgments

Thanks to the Mozilla team and the PDF.js project for their excellent work and for providing a robust viewer that this package builds on.