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 🙏

© 2024 – Pkg Stats / Ryan Hefner

pdf-viewer-web-component

v0.0.23

Published

PDF viewer as a web component build with Stencil and Pdf.js.

Downloads

45

Readme

PDF viewer widget

Embeddable widget which displays a browsable PDF preview using Web Components built with Stencil and PDF.js.

Check out the Stencil docs for the various build types.

Usage

Vanilla HTML/JS

<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0">
  <title>Widget</title>

  <script type="module" src="/build/pdf-viewer.esm.js"></script>
  <script nomodule src="/build/pdf-viewer.js"></script>

</head>
<body>

  <div style="width: 600px;">
    <pdf-viewer
      canvas-width="600"
      url="http:://example.org/file.pdf"
    >
    </pdf-viewer>
  </div>

</body>
</html>

NPM package in React application

Component JSX:

  <div style="width: 600px;">
    <pdf-viewer
      canvas-width="600"
      url="http:://example.org/file.pdf"
    >
    </pdf-viewer>
  </div>

index.js:

import { applyPolyfills, defineCustomElements } from 'pdf-viewer-web-component/dist/loader'

render(
  <App />, document.getElementById('root')
)

applyPolyfills().then(() => {
  defineCustomElements(window)
})

Install

Tested with Node v12.13.0

npm install

Development

Do the following steps in order embed a locally served PDF:

  1. Download this PDF into a folder
  2. CD into the folder
  3. npm install -g http-server
  4. Run command http-server --cors -p 8081 to serve the example PDF. Make sure the PDF is served at http://localhost:8081/Personal-Data-Political-Persuasion-How-it-works.pdf
  5. Open a new terminal and CD into this project directory
  6. Run npm run dev to open a browser which displays the widget with the PDF.

Production

To build the component for production, run:

npm run build

It is important to run npm run build before npm run publish otherwise not all files get included in the distribution.

Tests

To run the unit and end to end tests for the components, run:

npm run test

Troubleshooting

  • Update to Webpack 4.41.2 in case you are using webpack and the npm package of this and get a Can't import the named export 'a' from non EcmaScript module (only default export is available) error.