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

react-pdf-scrolling-pages

v1.0.2

Published

Simple React component to wrap up PDF.js. The easiest way to render all pages of a PDF in your React app. Comes with default styling.

Downloads

11

Readme

react-pdf-scrolling-pages

Easily scroll through the list of pages in a pdf using a mouse scroll or keyboard. Display your pdf as easily as if they were images. Comes with built-in 3d styling for quick setup. You can also do your own custom styling using a className and CSS.

Uses PDF.js.

New 09/21/2024


NPM Version NPM Downloads

Demo

Demo can be found here.

Usage

Install with yarn add react-pdf-scrolling-pages or npm install react-pdf-scrolling-pages

usePdf hook

Use the hook in your app (comes with built-in 3d page look out of the box):

import './App.css';
import { usePdf } from 'react-pdf-scrolling-pages';

function App() {
  const { pdfDocument } = usePdf({
    file: 'sample.pdf',
    pdfLocation: 'pdfdoc',
  });

  return (
    <>
      <div>{pdfDocument ? <div id="pdfdoc"></div> : <></>}</div>
    </>
  );
}

export default App;

Props

When you call usePdf you'll want to pass in a subset of these props, like this:

const { pdfDocument } = usePdf({ pdfLocation: 'pdfdoc', file: 'https://example.com/test.pdf' });

pdfLocation

an id of an html element where you want your pages to display.

file

URL of the PDF file.

onDocumentLoadSuccess

Allows you to specify a callback that is called when the PDF document data will be fully loaded. Callback is called with PDFDocumentProxy as an only argument.

onDocumentLoadFail

Allows you to specify a callback that is called after an error occurred during PDF document data loading.

onInvalidLocation

Allows you to specify a callback that is called if the pdfLocation html element is not found.

scale

Allows you to scale the PDF. Default = 1.

rotate

Allows you to rotate the PDF. Number is in degrees. Default = 0.

cMapUrl

Allows you to specify a cmap url. Default = '../node_modules/pdfjs-dist/cmaps/'.

cMapPacked

Allows you to specify whether the cmaps are packed or not. Default = false.

workerSrc

Allows you to specify a custom pdf worker url. Default = '//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js'.

withCredentials

Allows you to add the withCredentials flag. Default = false.

className

Allows you to style your pdf pages by passing in a className.

useDefaultStyle (defaults to true)

Specifies whether to use the built-in styling or not to use the built-in styling.

Returned values

pdfDocument

pdfjs's PDFDocumentProxy object. This can be undefined if document has not been loaded yet.

This is the equivelant css of the default built in styling:

.pdfClass {
  display: block;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 1em;
  border-radius: 10px;
  border: 2px solid;
  align-content: center;
  align-items: center;
  box-shadow: rgba(22, 31, 39, 0.42) 0px 60px 123px -25px, rgba(
        19,
        26,
        32,
        0.08
      ) 0px 35px 75px -35px;
  border-color: rgb(213, 220, 226) rgb(213, 220, 226) rgb(184, 194, 204);


# License

MIT © [pvanweel2997](https://github.com/pvanweel2997)